Re: [R-pkg-devel] Advice on elegant way to alias function name

2022-09-01 Thread Uwe Ligges




On 01.09.2022 16:48, J C Nash wrote:

Hi,

I've a package where it has been suggested that one of the functions -- 
call
it "myfn()" -- should be called something else, say "thefn()". Of 
course, I'll

need to keep the old name around for a while.

Web search has suggested simple assignment of

     thefn <- myfn

but I cannot seem to get this to work with R CMD check when I put this 
in a .R
file in the code and put alias and usage stanzas in documentation. I get 
alias
and missing argument type errors. I've tried a number of variations on 
this theme

without appreciable success.


Can you make the package available? It should work.

Best,
Uwe


A workaround is to copy the entire function with Roxygen2 documentation and
name change, but this seems inelegant.

Is there a better way e.g., using something like onLoad ? Pointers to 
working

examples in CRAN or Github packages would be welcome.

Best, JN

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Advice on elegant way to alias function name

2022-09-01 Thread Sokol Serguei

Le 01/09/2022 à 16:48, J C Nash a écrit :

Hi,

I've a package where it has been suggested that one of the functions 
-- call
it "myfn()" -- should be called something else, say "thefn()". Of 
course, I'll

need to keep the old name around for a while.

Web search has suggested simple assignment of

    thefn <- myfn

but I cannot seem to get this to work with R CMD check when I put this 
in a .R

file in the code and put alias and usage stanzas in documentation.


Is there any place where we can see what alias and stanzas you have used 
actually?


Best,
Serguei.


I get alias
and missing argument type errors. I've tried a number of variations on 
this theme

without appreciable success.

A workaround is to copy the entire function with Roxygen2 
documentation and

name change, but this seems inelegant.

Is there a better way e.g., using something like onLoad ? Pointers to 
working

examples in CRAN or Github packages would be welcome.

Best, JN

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Advice on elegant way to alias function name

2022-09-02 Thread John Fox

Dear John,

I've used an alternative solution in similar situations, equivalent to 
defining


thefn <- function(...) myfn(...)

Then only ... needs to be documented as arguments passed down to myfn(). 
Maybe that would work for you too.


Best,
 John

On 2022-09-02 4:22 p.m., J C Nash wrote:

With some playing around I found a workable solution.

- NAMESPACE needs  export(thefn)
- thefn.Rd needs usage and arguments documented
- myfn.Rd must NOT have alias(thefn)

And I believe I've got the roxygen2 tags to work in Rstudio. In R itself,
roxygen2 gives an error
     Error: invalid version specification ‘0.68’
though the string '0.68' appears nowhere in my package according to grep.
I have no idea what this is about, especially as Rstudio works fine.

While I like the idea of documentation in code files, I think I'll go
back to separately created .Rd files.

If anyone is interested, package and README are at
https://gitlab.com/nashjc/nlsr2022

Best,

John Nash


On 2022-09-01 11:29, Hadley Wickham wrote:

On Thu, Sep 1, 2022 at 9:48 AM J C Nash  wrote:


Hi,

I've a package where it has been suggested that one of the functions 
-- call
it "myfn()" -- should be called something else, say "thefn()". Of 
course, I'll

need to keep the old name around for a while.

Web search has suggested simple assignment of

  thefn <- myfn

but I cannot seem to get this to work with R CMD check when I put 
this in a .R
file in the code and put alias and usage stanzas in documentation. I 
get alias
and missing argument type errors. I've tried a number of variations 
on this theme

without appreciable success.

A workaround is to copy the entire function with Roxygen2 
documentation and

name change, but this seems inelegant.


You'll also need to add a couple of roxygen tags:

#' @export
#' @rdname myfn
thefn <- myfn

Hadley



__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel