Re: [R-pkg-devel] Accessing features in R4.0.

2020-12-16 Thread Gábor Csárdi
On Wed, Dec 16, 2020 at 8:39 PM Henrik Bengtsson
 wrote:
>
> BTW, 'backports' provides a backport for tools::R_user_dir() also for
> R (< 4.0.0), so an alternative solution in this case is:
>
> Imports: backports
>
> and
>
> importFrom(backports, R_user_dir)
>
> The 'backports' package takes the same approach as I did in my previous 
> message.

FWIW, the backports README actually suggests a different approach:
https://github.com/r-lib/backports#in-packages

G.

[...]

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


Re: [R-pkg-devel] Accessing features in R4.0.

2020-12-16 Thread Henrik Bengtsson
BTW, 'backports' provides a backport for tools::R_user_dir() also for
R (< 4.0.0), so an alternative solution in this case is:

Imports: backports

and

importFrom(backports, R_user_dir)

The 'backports' package takes the same approach as I did in my previous message.

Henrik

On Wed, Dec 16, 2020 at 12:27 PM Henrik Bengtsson
 wrote:
>
> Colin, you can do:
>
> Imports: tools
>
> NAMESPACE:
> if (getRversion() >= 4) importFrom(tools,R_user_dir)
>
>
> R/000.namespace.R:
> ## Create a dummy R_user_dir() for R (< 4.0.0)
> ## to please R CMD check
> if (getRversion() < 4) {
>   R_user_dir <- function(...) NULL
> }
>
> and then use:
>
> if (getRversion() < 4) {
>   # do something
> } else {
>   R_user_dir("oysteR", which = "cache")
> }
>
> An advantage of this approach is that it's clear from Imports: and the
> NAMESPACE file what you're importing and when.  When using Suggests:
> and pkg::fcn() you can't peek at NAMESPACE to see what's actually
> used.
>
>
> Finally, if '#do something' is basically trying to do the same as
> tools::R_user_dir(), you could of course also consider writing your
> own forward-compatible wrapper for R (< 4.0.0), e.g.
>
> if (getRversion() < 4) {
>   R_user_dir <- function(...) {
> # do something
>}
> }
>
> and then use R_user_dir() as if you're running R (>= 4.0.0).  That's
> the cleanest version.
>
> Hope this helps,
>
> Henrik
>
>
> On Wed, Dec 16, 2020 at 11:12 AM Jeff Newmiller
>  wrote:
> >
> > For "obvious" reasons? I don't see this kind of avoidance as "obviously" 
> > correct at all. You have a dependency... it should be declared. There are 
> > various ways to proceed, with Imports or Depends or Suggests or pulling the 
> > code into your package... but trying to subvert the dependency management 
> > is counterproductive.
> >
> > On December 16, 2020 8:28:15 AM PST, Colin Gillespie 
> >  wrote:
> > >Hi,
> > >
> > >I'm planning on using the tools::R_user_dir function in a package. But
> > >for obvious reasons, I don't want to set the dependency on R 4.
> > >
> > >My code is basically
> > >
> > >if (as.numeric(R.version$major) < 4) # do something
> > >else tools::R_user_dir("oysteR", which = "cache")
> > >
> > >When checking on win-builder R3.6 I get the note
> > >
> > >* checking dependencies in R code ... NOTE
> > >Missing or unexported object: 'tools::R_user_dir'
> > >
> > >## Question
> > >
> > >Is my code correct and can I ignore this note?
> > >
> > >Thanks
> > >
> > >Colin
> > >
> > >
> > >Dr Colin Gillespie
> > >http://www.mas.ncl.ac.uk/~ncsg3/
> > >
> > >__
> > >R-package-devel@r-project.org mailing list
> > >https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >
> > --
> > Sent from my phone. Please excuse my brevity.
> >
> > __
> > 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] Accessing features in R4.0.

2020-12-16 Thread Henrik Bengtsson
Colin, you can do:

Imports: tools

NAMESPACE:
if (getRversion() >= 4) importFrom(tools,R_user_dir)


R/000.namespace.R:
## Create a dummy R_user_dir() for R (< 4.0.0)
## to please R CMD check
if (getRversion() < 4) {
  R_user_dir <- function(...) NULL
}

and then use:

if (getRversion() < 4) {
  # do something
} else {
  R_user_dir("oysteR", which = "cache")
}

An advantage of this approach is that it's clear from Imports: and the
NAMESPACE file what you're importing and when.  When using Suggests:
and pkg::fcn() you can't peek at NAMESPACE to see what's actually
used.


Finally, if '#do something' is basically trying to do the same as
tools::R_user_dir(), you could of course also consider writing your
own forward-compatible wrapper for R (< 4.0.0), e.g.

if (getRversion() < 4) {
  R_user_dir <- function(...) {
# do something
   }
}

and then use R_user_dir() as if you're running R (>= 4.0.0).  That's
the cleanest version.

Hope this helps,

Henrik


On Wed, Dec 16, 2020 at 11:12 AM Jeff Newmiller
 wrote:
>
> For "obvious" reasons? I don't see this kind of avoidance as "obviously" 
> correct at all. You have a dependency... it should be declared. There are 
> various ways to proceed, with Imports or Depends or Suggests or pulling the 
> code into your package... but trying to subvert the dependency management is 
> counterproductive.
>
> On December 16, 2020 8:28:15 AM PST, Colin Gillespie  
> wrote:
> >Hi,
> >
> >I'm planning on using the tools::R_user_dir function in a package. But
> >for obvious reasons, I don't want to set the dependency on R 4.
> >
> >My code is basically
> >
> >if (as.numeric(R.version$major) < 4) # do something
> >else tools::R_user_dir("oysteR", which = "cache")
> >
> >When checking on win-builder R3.6 I get the note
> >
> >* checking dependencies in R code ... NOTE
> >Missing or unexported object: 'tools::R_user_dir'
> >
> >## Question
> >
> >Is my code correct and can I ignore this note?
> >
> >Thanks
> >
> >Colin
> >
> >
> >Dr Colin Gillespie
> >http://www.mas.ncl.ac.uk/~ncsg3/
> >
> >__
> >R-package-devel@r-project.org mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> 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] Accessing features in R4.0.

2020-12-16 Thread Jeff Newmiller
For "obvious" reasons? I don't see this kind of avoidance as "obviously" 
correct at all. You have a dependency... it should be declared. There are 
various ways to proceed, with Imports or Depends or Suggests or pulling the 
code into your package... but trying to subvert the dependency management is 
counterproductive.

On December 16, 2020 8:28:15 AM PST, Colin Gillespie  
wrote:
>Hi,
>
>I'm planning on using the tools::R_user_dir function in a package. But
>for obvious reasons, I don't want to set the dependency on R 4.
>
>My code is basically
>
>if (as.numeric(R.version$major) < 4) # do something
>else tools::R_user_dir("oysteR", which = "cache")
>
>When checking on win-builder R3.6 I get the note
>
>* checking dependencies in R code ... NOTE
>Missing or unexported object: 'tools::R_user_dir'
>
>## Question
>
>Is my code correct and can I ignore this note?
>
>Thanks
>
>Colin
>
>
>Dr Colin Gillespie
>http://www.mas.ncl.ac.uk/~ncsg3/
>
>__
>R-package-devel@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-package-devel

-- 
Sent from my phone. Please excuse my brevity.

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


Re: [R-pkg-devel] Accessing features in R4.0.

2020-12-16 Thread Sebastian Meyer
Am 16.12.20 um 18:00 schrieb Neal Fultz:
> IIRC some packages use get() instead of double-colon to suppress the NOTE.

I'd discourage from using get() because you could (accidentally) access
even unexported objects from another namespace. There is

getExportedValue(ns, name)

to avoid that. However, its help page describes it as an internal
function, so I'm not sure if that would be any better. "::" access is
also faster, especially as of the next version of R.

Of course, such workarounds should be used with great care as these
checks are usually very valuable to guard against coding errors or warn
about potential changes in the other package's API.

> I would probably ignore it myself.

Yes. FWIW, conditional use of tools::R_user_dir() is allowed according
to the CRAN repository policy:

> For R version 4.0 or later (hence a version dependency is required or only 
> conditional use is possible), packages may store user-specific data, 
> configuration and cache files in their respective user directories obtained 
> from tools::R_user_dir(), provided that by default sizes are kept as small as 
> possible and the contents are actively managed (including removing outdated 
> material). 

Best regards,

Sebastian Meyer


> 
> On Wed, Dec 16, 2020 at 8:29 AM Colin Gillespie  wrote:
>>
>> Hi,
>>
>> I'm planning on using the tools::R_user_dir function in a package. But
>> for obvious reasons, I don't want to set the dependency on R 4.
>>
>> My code is basically
>>
>> if (as.numeric(R.version$major) < 4) # do something
>> else tools::R_user_dir("oysteR", which = "cache")
>>
>> When checking on win-builder R3.6 I get the note
>>
>> * checking dependencies in R code ... NOTE
>> Missing or unexported object: 'tools::R_user_dir'
>>
>> ## Question
>>
>> Is my code correct and can I ignore this note?
>>
>> Thanks
>>
>> Colin
>>
>>
>> Dr Colin Gillespie
>> http://www.mas.ncl.ac.uk/~ncsg3/
>>
>> __
>> 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
>

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


Re: [R-pkg-devel] Accessing features in R4.0.

2020-12-16 Thread Neal Fultz
IIRC some packages use get() instead of double-colon to suppress the NOTE.

I would probably ignore it myself.

On Wed, Dec 16, 2020 at 8:29 AM Colin Gillespie  wrote:
>
> Hi,
>
> I'm planning on using the tools::R_user_dir function in a package. But
> for obvious reasons, I don't want to set the dependency on R 4.
>
> My code is basically
>
> if (as.numeric(R.version$major) < 4) # do something
> else tools::R_user_dir("oysteR", which = "cache")
>
> When checking on win-builder R3.6 I get the note
>
> * checking dependencies in R code ... NOTE
> Missing or unexported object: 'tools::R_user_dir'
>
> ## Question
>
> Is my code correct and can I ignore this note?
>
> Thanks
>
> Colin
>
>
> Dr Colin Gillespie
> http://www.mas.ncl.ac.uk/~ncsg3/
>
> __
> 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] Accessing features in R4.0.

2020-12-16 Thread brodie gaslam via R-package-devel
I don't know if this will work in your case (or even if it is a good
or bad thing to do), but backports conditionally exports the function
in question, e.g.:

https://github.com/r-lib/backports/blob/master/R/lengths.R

So in that example their implementation of a function not available
in R < 3.2.0 is presumably only exported for those versions of R.
You could try something similar, although I make no guarantees
on whether this is considered proper or not.  It _seems_ like
a clean solution to me, but I have no experience putting any
logic in the namespace file.

WRE does show something very similar, so this might be okay:

https://cran.r-project.org/doc/manuals/R-exts.html#Registering-S3-methods

Best,

B.



On Wednesday, December 16, 2020, 11:29:08 AM EST, Colin Gillespie 
 wrote: 





Hi,

I'm planning on using the tools::R_user_dir function in a package. But
for obvious reasons, I don't want to set the dependency on R 4.

My code is basically

if (as.numeric(R.version$major) < 4) # do something
else tools::R_user_dir("oysteR", which = "cache")

When checking on win-builder R3.6 I get the note

* checking dependencies in R code ... NOTE
Missing or unexported object: 'tools::R_user_dir'

## Question

Is my code correct and can I ignore this note?

Thanks

Colin


Dr Colin Gillespie
http://www.mas.ncl.ac.uk/~ncsg3/

__
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


[R-pkg-devel] Accessing features in R4.0.

2020-12-16 Thread Colin Gillespie
Hi,

I'm planning on using the tools::R_user_dir function in a package. But
for obvious reasons, I don't want to set the dependency on R 4.

My code is basically

if (as.numeric(R.version$major) < 4) # do something
else tools::R_user_dir("oysteR", which = "cache")

When checking on win-builder R3.6 I get the note

* checking dependencies in R code ... NOTE
Missing or unexported object: 'tools::R_user_dir'

## Question

Is my code correct and can I ignore this note?

Thanks

Colin


Dr Colin Gillespie
http://www.mas.ncl.ac.uk/~ncsg3/

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