Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRAN complains about user_cache_dir() #27

Closed
wch opened this issue Jan 15, 2021 · 8 comments · Fixed by #30
Closed

CRAN complains about user_cache_dir() #27

wch opened this issue Jan 15, 2021 · 8 comments · Fixed by #30

Comments

@wch
Copy link
Member

wch commented Jan 15, 2021

We got this message from CRAN when we used rappdirs::user_cache_dir():

Also, checking creates and leaves behind
   ~/.cache/R-bslib
in violation of the CRAN Policy's
   Packages should not write in the user's home filespace (including
   clipboards), nor anywhere else on the file system apart from the R
   session's temporary directory (or during installation in the location
   pointed to by TMPDIR: and such usage should be cleaned up). Installing
   into the system's R installation (e.g., scripts to its bin directory)
   is not allowed.
   Limited exceptions may be allowed in interactive sessions if the
   package obtains confirmation from the user.
   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).
Can you please change as necessary, ideally using the
tools::R_user_dir() mechanism where available?

The code is here:
https://github.com/rstudio/bslib/blob/80a5059bcef0bec16c9d914b6458f70077d2707b/R/fonts.R#L387

@gaborcsardi has said that we should stick with rappdirs, since tools::R_user_dir() doesn't always do the right thing on Windows, but this is causing problems with packages submitted to CRAN.

For the record, on my Mac:

> R.version.string
[1] "R version 4.0.3 (2020-10-10)"
> tools::R_user_dir('foo', which = 'cache')
[1] "/Users/winston/Library/Caches/org.R-project.R/R/foo"
> rappdirs::user_cache_dir('foo')
[1] "/Users/winston/Library/Caches/foo"

And on Linux (using the wch1/r-debug docker image):

> R.version.string
[1] "R Under development (unstable) (2021-01-14 r79827)"
> tools::R_user_dir('foo', which = 'cache')
[1] "/root/.cache/R/foo"
> rappdirs::user_cache_dir('foo')
[1] "/root/.cache/foo"

cc @cpsievert, @schloerke

@cderv
Copy link

cderv commented Jan 18, 2021

And this is on Windows:

R.version.string
#> [1] "R version 4.0.3 (2020-10-10)"
tools::R_user_dir('foo', which = 'cache')
#> [1] "C:\\Users\\chris\\AppData\\Local/R/cache/R/foo"
rappdirs::user_cache_dir('foo')
#> [1] "C:\\Users\\chris\\AppData\\Local\\foo\\foo\\Cache"

@gaborcsardi
Copy link
Member

gaborcsardi commented Jan 18, 2021

rappdirs uses the <author> / <app> convention on Windows, which is what most software packages use. E.g.

C:/Users/csard/AppData/Local/Adobe/Acrobat
C:/Users/csard/AppData/Local/Microsoft/Office

If you don't want the <author> part, then supply NULL there:

> rappdirs::user_cache_dir('R', NULL)
[1] "C:\\Users\\csard\\AppData\\Local\\R\\Cache"

I am not entirely sure why R_user_dir() adds another R subdirectory, but if you want to do it the same way, you can of course:

> file.path(rappdirs::user_cache_dir('R', NULL), "R", "foo")
[1] "C:\\Users\\csard\\AppData\\Local\\R\\Cache/R/foo"

Or you can also use tools::R_user_dir() instead of rappdirs, in most cases it is completely fine.

@gaborcsardi
Copy link
Member

As for leaving files around, it is good practice to support an environment variable to specify the cache/config location, and you can set this to a temporary directory at the beginning of your tests, and then clean it up after the tests.

@hadley
Copy link
Member

hadley commented Jan 18, 2021

(@gaborcsardi The reason we can't use tools::R_user_dir() is that it only works on >= 4.0.0)

@gaborcsardi
Copy link
Member

gaborcsardi commented Jan 18, 2021 via email

@hadley
Copy link
Member

hadley commented Jan 18, 2021

We should provide a backport somewhere, although I'm not sure if it should go here or in backports.

I wonder if fixing this issue just requires teaching rappdirs to respect R_USER_CACHE_DIR and friends, which I'm guess are set on CRAN.

@gaborcsardi
Copy link
Member

I think you are right. Having such an env var would make sense in general, anyway.

hadley added a commit that referenced this issue Jan 18, 2021
hadley added a commit that referenced this issue Jan 18, 2021
@hadley
Copy link
Member

hadley commented Jan 18, 2021

I'm pretty sure the root cause of the issue is not respecting the env vars that I think CRAN is setting, but I've also emailed Kurt to double check, and opened r-lib/backports#55 since folks now can just use the R implementation directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants