1

i have an R script that looks like this:

install.packages("R.utils")
library("R.utils")
install.packages("vcfR")
library("vcfR")
install.packages("stringr")
library("stringr")
install.packages("tidyverse")
library("tidyverse")
install.packages("dplyr")
library("dplyr")
gunzip("gnomad.exomes.r2.1.1.sites.21.vcf.bgz", "gnomad.exomes.r2.1.1.sites.21.vcf")
vc=read.vcfR("gnomad.exomes.r2.1.1.sites.21.vcf")
df=vc@fix
data=as.data.frame(df)
data_snp=data %>%
  filter(str_length(ALT)==1 & str_length(REF)==1)#filtering for SNPs
data_snp$snp_id <- str_c("chr21","-", data_snp$POS)
data_snp$AF_total=str_extract(data_snp$INFO, "(?<=AF=)[^;]+")
data_snp$AF_latin=str_extract(data_snp$INFO, "(?<=AF_amr=)[^;]+")
data_snp$INFO=NULL
data_snp$key=str_c(data_snp$snp_id,"-",data_snp$ALT,"-",data_snp$REF)
df_for_filter=read.csv("merged_df.csv")
df_x=subset(df_for_filter,df_for_filter$CHROM=="chr21")
df_x$snp_id=str_c("chr21","-",df_x$POS)
df_x$key=str_c(df_x$snp_id,"-",df_x$ALT,"-",df_x$REF)
filter_df=data_snp %>% semi_join(df_x, by = "key")
results=read.csv("result_armitage_test.csv")
results$chrom=substr(results$snp_id,1,5)
results_y=subset(results,results$chrom=="chr21")
resuts_21=merge(x = results_y, y =filter_df, by = "snp_id", all.x = TRUE)
resuts_21$CHROM=NULL
resuts_21$POS=NULL
resuts_21$CHROM=NULL
resuts_21$FILTER=NULL
resuts_y$QUAL=NULL
resuts_21$key=NULL
write.csv(resuts_21,"result_chr21.csv")

i run this script in UBUNTU :

xxxxx@xxxx:~% Rscrips chr_21.R

but it returns an error :

CORRECT>Rscript chr_21.R (y|n|e|a)? yes
Installing package into ‘/usr/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("R.utils") :
  'lib = "/usr/lib/R/site-library"' is not writable
Error in install.packages("R.utils") : unable to install packages
Execution halted

I cant understand what is wrong why the library cant be installed and how to fix this .thank you:)

17
  • what are the permissions on /usr/lib/R/site-library?
    – Esther
    Commented Nov 21, 2022 at 16:49
  • @Esther how do i check the premissions? sorry im new to UBUNTU Commented Nov 21, 2022 at 16:51
  • ls -ld /usr/lib/R/site-library will do it
    – Esther
    Commented Nov 21, 2022 at 16:51
  • @Esther drwxr-xr-x 122 root root 2941 Mar 2 2021 /usr/lib/R/site-library/ Commented Nov 21, 2022 at 16:52
  • 1
    If you are working on a university cluster, you will likely need to ask the system's administrators to install the packages for you - or else configure R to use a local (user) library location (perhaps by creating a ~/.Renviron file specifying an R_LIBS_USER path?) Commented Nov 21, 2022 at 18:09

1 Answer 1

2

If you are working on a university cluster, you will likely need to ask the system's administrators to install the packages site-wide - or else configure R to install packages to a local (user) library location.

If you haven't already set up a local library, then the easiest way seems to be to execute R interactively, attempt to install a package, and follow the instructions when site-wide installation fails.

First, start R and check the current library search path:

> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"      
[3] "/usr/lib/R/library"

OK now let's try to install the stringr package:

> install.packages("stringr")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("stringr") :
  'lib = "/usr/local/lib/R/site-library"' is not writable

(it fails, then prompts)

Would you like to use a personal library instead? (yes/No/cancel) yes
Would you like to create a personal library
‘/home/steeldriver/R/x86_64-pc-linux-gnu-library/4.2’ to install packages into? (yes/No/cancel) yes
also installing the dependencies ‘glue’, ‘magrittr’, ‘stringi’

(after some time)

* DONE (stringr)

The downloaded source packages are in
        ‘/tmp/RtmpsVbbe1/downloaded_packages’
> 

Now you can check that the newly-created libPath has been added:

> 
> .libPaths()
[1] "/home/steeldriver/R/x86_64-pc-linux-gnu-library/4.2"
[2] "/usr/local/lib/R/site-library"                      
[3] "/usr/lib/R/site-library"                            
[4] "/usr/lib/R/library"

FWIW the default user library location seems to come from a template in the /etc/R/ environment files:

$ grep R_LIBS_USER /etc/R/*
/etc/R/Renviron:R_LIBS_USER=${R_LIBS_USER:-'%U'}
/etc/R/Renviron.site:#R_LIBS_USER=${R_LIBS_USER-'~/R/@R_PLATFORM@-library/@MAJ_MIN_VERSION@'}

Once you've done that for one package, your script should run and install the rest to your new user library.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .