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

Renviron and littler #64

Closed
csgillespie opened this issue Jan 1, 2019 · 10 comments
Closed

Renviron and littler #64

csgillespie opened this issue Jan 1, 2019 · 10 comments

Comments

@csgillespie
Copy link
Contributor

It appears that littler doesn't read .Renviron files
.
I would offer a PR, but my C is probably not good enough for https://github.com/eddelbuettel/littler/blob/master/src/littler.c

Two asides:

  • An easy workaround is to add readRenviron("~/.Renviron") to ~/.littler.r
  • install2.rdoesn't follow the lib convention with install.packages() - a different default location. But it's probably far to late to consider changing that.
@eddelbuettel
Copy link
Owner

Can you expand on what does work for you for install2.r -- it's whole (initial) point was to offer the -l | --library flag, and it is the main usage reason.

If you mean that it doesn't follow R_LIBS_USER etc: yeah. That is a shortcut we took twelve years ago. Those values are read at compile time and fixed. They are part of why r (still) starts faster than Rscript. I see not reason to change that given that we all have Rscript available.

As for .Renviron: I probably looked into that at some point and said 'meh'. At one point I added littler-specific rc files and that was a bad idea. We now read some standard dot files and that seems good enough.

@eddelbuettel
Copy link
Owner

You could lean on R's src/main/Renviron.c -- but that is 300 lines.

And there is always ~/.Rprofile which we do read:

edd@rob:~$ grep Sys.setenv ~/.Rprofile
Sys.setenv(TZ="America/Chicago")
edd@rob:~$ r -p -e 'Sys.getenv("TZ")'
[1] "America/Chicago"
edd@rob:~$ 

@csgillespie
Copy link
Contributor Author

Yep, it was initially the R_LIBS_USER that caught me out. But I also keep all my API keys in the Renviron. I don't suggest changing the default -l behaviour - been around too long to break.

I think the easiest change for any future users is to use readRenviron("~/.Renviron") in the .littler.r file. Not sure if it's worth documenting somewhere?

Otherwise, close this issue. Ta.

@eddelbuettel
Copy link
Owner

Fair point on the documenting. I would rather not stress ~/.littler.r more, I consider that to be a bad detour. OTOH maybe it fits here.

I source my APIs explicitly by looping over snippets in ~/.R/profile.d/:

    if (dir.exists("~/.R/profile.d")) {
        files <- list.files("~/.R/profile.d", pattern=".*\\.R$", full.names=TRUE)
        for (f in files) {
            source(f)
        }
    }

and because the quoted code lives in ~/.Rprofile littler sees it too... Should document...

@HenrikBengtsson
Copy link

FYI, some env vars must be set no later than .Renviron. They will have no effect is if set in .Rprofile.

@eddelbuettel
Copy link
Owner

Right. The POSIX level call to set environment variables rarely affect the already running process.

@aparkerlue
Copy link

If you mean that it doesn't follow R_LIBS_USER etc: yeah. That is a shortcut we took twelve years ago.

If not R_LIBS_USER, what do you recommend using to set the library search path?

@eddelbuettel
Copy link
Owner

eddelbuettel commented Apr 25, 2019

I don't follow. What is your problem? What are you trying to do? What is failing?

edd@rob:~$ r -p -e '.libPaths()'
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"       "/usr/lib/R/library"
edd@rob:~$ R_LIBS_USER="/tmp" r -p -e '.libPaths()'
[1] "/tmp"                     "/usr/local/lib/R/site-library" 
[3] "/usr/lib/R/site-library"  "/usr/lib/R/library"
edd@rob:~$

There are also dedicated dot.rc files for littler (from way back when we didn't read the R-parseable ones). We simply don't parse Renviron because doing so .... requires many lines of code, and life is short. Plus, as documented in my demo above, what you appear to be looking for already works.

@aparkerlue
Copy link

@eddelbuettel—I misunderstood. I thought you meant that R_LIBS_USER was a shortcut you took twelve years ago, not Renviron. Thanks for elaborating.

Regarding what I am attempting to do and what is failing, I am trying to automatically add ~/.local/lib/x86_64-linux-gnu/R/3.5 to the R library search path when starting both R and littler. I take it that best practice is to setR_LIBS_USER in the shell environment, e.g. in ~/.profile or ~/.profile.d/R.sh.

I now keep

export R_LIBS_USER="~/.local/lib/%a-%o/R/%v"

in one of my shell startup files, and the output of .libPaths() is as intended.

@eddelbuettel
Copy link
Owner

I take it that best practice is to set R_LIBS_USER

Please help(Startup) carefully. There are bazillion R ways to do this including some that would carry over to littler as we do read some of the dot files (just not the Renviron variety).

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

No branches or pull requests

4 participants