Where does .Renviron live on Citrix?

January 7, 2019
By

(This article was first published on R on datawookie, and kindly contributed to R-bloggers)

At one of my clients I run RStudio under Citrix in order to have access to their data.

For the most part this works fine. However, every time I visit them I spend the first few minutes of my day installing packages because my environment does not seem to be persisted from one session to the next.

I finally had a gap and decided to fix the problem.

Where are the packages being installed?

Installed packages just spontaneously disappear… That’s weird. Where are they being installed?

# Install package under Citrix.
> install.packages("devtools")
Installing package into ‘C:/Users/andrewcol/Documents/R/win-library/3.5

It looks like the packages are being installed into a folder on my C: drive. But if I look for that folder it’s not there.

How does this make sense?

A bit of investigation revealed that the folder is actually on the C: drive on the Citrix server (rather than my local machine).

I confirmed this by installing the same package using RStudio running on my local machine.

# Install package on local.
> install.packages("devtools")
Installing package into ‘C:/Users/AndrewCol/Documents/R/win-library/3.4

Note the difference in the path (andrewcol versus AndrewCol) and R versions.

Environment

I know that files on my network H: drive will not disappear between sessions, so this seems like a natural place to install packages. I can make this happen by changing the R_LIBS_USER environment variable.

# Environment on Citrix.
> Sys.getenv("R_LIBS_USER")
[1] "C:/Users/andrewcol/Documents/R/win-library/3.5"

We’ll assign a new value by setting up a .Renviron file. Where should this file live? On my local C: drive, my network H: drive or the Citrix server C: drive?

# Environment on Citrix.
> Sys.getenv("R_USER")
[1] "C:/Users/andrewcol/Documents"

Okay, so it needs to go on the Citrix C: drive. This is really the crux of the entire process, because if you put it on H: or local C: then it will not be picked up by RStudio on Citrix.

Writing to Citrix C:

It turns out that it’s remarkably difficult to access C: on the Citrix server. I couldn’t get there using File Explorer. I couldn’t create a new file there using Notepad or RStudio.

No problem! Write an R script.

renviron <- file("C:/Users/andrewcol/Documents/.Renviron", "w")
cat(
    "R_LIBS_USER='H:/myCitrixFiles/Documents/R/win-library/3.5'",
    "R_USER='H:/myCitrixFiles/Documents'",
    file = renviron,
    sep = "\n"
)
close(renviron)

That’ll create the .Renviron file in the right place and insert the required content.

Quick check that it’s been created.

setwd("C:/Users/andrewcol/Documents")
list.files(all.files = TRUE)
readLines(".Renviron")

Restart RStudio under Citrix. Packages will be installed to H: and should not mysteriously disappear between sessions.

To leave a comment for the author, please follow the link and comment on their blog: R on datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)