由于安装了软件包,从UBUNTU运行R脚本失败

问题描述

我正在尝试从Ubuntu运行R脚本。 R脚本使用vcfR库:

install.packages("vcfR")
library("vcfR")

vcf.rout<-"/mnt/c/Users/PC/Documents/aDNA/haplotypes.vcf"
vcf<-read.vcfR(vcf.rout)

当我在R中运行脚本时,它运行良好, 但是当我在Ubuntu中运行脚本时,出现此错误

batelziv@DESKTOP-PGCKNUM:~$ Rscript /mnt/c/Users/PC/Documents/aDNA/Rs/unt1.R <br />
Installing package into ‘/usr/local/lib/R/site-library’<br />
(as ‘lib’ is unspecified)<br />
Warning in install.packages("vcfR") :<br />
'lib = "/usr/local/lib/R/site-library"' is not writable<br />
Error in install.packages("vcfR") : unable to install packages<br />
Execution halted

我还尝试了在没有库相关行的情况下运行脚本:

library("vcfR")

vcf.rout<-"/mnt/c/Users/PC/Documents/aDNA/haplotypes.vcf"
vcf<-read.vcfR(vcf.rout)

我得到:

    Error in library("vcfR") : there is no package called ‘vcfR’
    Execution halted

为什么Ubuntu无法使用已经安装的软件包?
为何安装时遇到问题?

解决方法

您有一个错误

'lib =“ / usr / local / lib / R / site-library”'不可读

您无权将软件包写入此路径。 我认为在安装时,您可以在其他路径中添加选项lib或检查是否无法写入。

install.packages(pkgs,lib = ...)