knitr::opts_chunk$set(echo = TRUE,  
                                            comment="      ##",  
                                            error=TRUE, 
                                            collapse=TRUE) 
library(data.table)
library(magrittr)

Problem

Normally, I use neovim + plugin nvim-R as my IDE. Recently I tried to install RStudio but ran into errors.

Directories

Seems each time I update R, I run into trouble with one or more directories that R uses. The reasons probably relate to the past of switching from RStudio to neovim or compiling from source one time and using binaries the next.

Over time, my R setup has collected diretories with various permuations of "lib", "library", "local." Rather than sort it all out, I decided to remove R and begin again.

I found this the Ubuntu/Debian instructions helpful: https://ftp.osuosl.org/pub/cran/bin/linux/debian, which explains some of R environmental variables.

Organization

So here I collect useful R environment variables I found to be important. To ease navigation, I also set shell environment variables (I use zsh ) to match R.

Of course, your experience will differ, but getting a good grasp on the R environment variables may avoid some future pain.

R_env  <- c("R_HOME", 
            "R_LIBS_USER", 
            "R_LIBS_SITE",
            NA,
            NA) 

paths  <- c("/usr/lib/R/",
            "/home/jim/R/x86_64-pc-linux-gnu-library/4.1/",
            "/usr/lib/R/library/",
            "/etc/R/Renviron",
            "~/.Renviron")

zsh_env  <- c("R_HOME", 
            "R_LIBS_USER", 
            "R_LIBS_SITE",
            NA,
            NA)



dt  <- data.table(R_env = R_env,
                  path = paths,
                  zsh_env = zsh_env)
dt %>% knitr::kable()

Special notes

Checking

Here is one way to confirm which directories R is using for packages.

.libPaths()

Another way is through Sys.getenv() to find R env variables

s  <- Sys.getenv()
names  <- names(s)
head(names)
head(s[grep(pattern = "^R", x = names)])
s[grep(pattern = "^R_LIBS", x = names)]
s[grep(pattern = "^R_LIBS", x = names)]
if (F) help(.libPaths)

Troubleshooting

knitr::knit_exit()

(got me into trouble) Upgrade R from 4.0.3 to 4.0.4

{
file <- "/home/jim/code/jimTools/rmd/0999_R_upgrade_notes.rmd"
file <- "rmd/0999_R_upgrade_notes.rmd"
file  <- basename(file)
file
file  <- paste0("rmd/",file)
file
}
file <- "rmd/0999_R_upgrade_notes.rmd"
rmarkdown::render(file, 
                  output_format="html_document",
                  #output_format="pdf_document",
                  output_dir="~/Downloads/print_and_delete")


jimrothstein/jimTools documentation built on Jan. 19, 2025, 3:23 p.m.