Score:1

Installing packages of R in UBUNTU

ir flag

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:)

Esther avatar
es flag
what are the permissions on `/usr/lib/R/site-library`?
Eliza Romanski avatar
ir flag
@Esther how do i check the premissions? sorry im new to UBUNTU
Esther avatar
es flag
`ls -ld /usr/lib/R/site-library` will do it
Eliza Romanski avatar
ir flag
@Esther drwxr-xr-x 122 root root 2941 Mar 2 2021 /usr/lib/R/site-library/
ar flag
In general you will need admin rights to install anything in the system folders like `/usr/lib/R/site-library/`.
Eliza Romanski avatar
ir flag
@Esther so there is nothing i can do ?
Esther avatar
es flag
You would need `sudo` to install stuff in that folder, since it is owned by `root` and only writable by `root`. This is assuming you actually want the libs to be installed there, and not somewhere else.
Eliza Romanski avatar
ir flag
@Esther how can i use sudo , wht are the steps , again sorry im new to unix and the whole environment
Eliza Romanski avatar
ir flag
@user68186 should i enter the command in the UBUNTU terminal?
Eliza Romanski avatar
ir flag
@user68186 adduser: Command not found. - returns , im using my university cluster maybe it doesnt work on it?
Eliza Romanski avatar
ir flag
@user68186 how do i check the version?
Eliza Romanski avatar
ir flag
@user68186 is it OK in terms of privecy to use the sudo usermod -a -G staff command on univerity cluster?
Eliza Romanski avatar
ir flag
@user68186 No LSB modules are available.
ar flag
That is fine. This command should give you the Ubuntu version in any case. I don't understand why you get command not found for `adduser`.
hr flag
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?)
hr flag
@user68186 likely `adduser` is not found because `/usr/sbin` is not in their `PATH` (since they are an unprivileged user)
ar flag
@steeldriver thanks for the clarification. I didn't think of the possibility of in school use. Your explanation and the answer below makes sense.
Score:1
hr flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.