R自定义包从文件安装错误

4
我一直在为一个仿真项目开发一个 R 包。在家里的电脑上,我使用 RStudio 成功地构建和安装了它。然而,在大学的另一台机器上,我遇到了问题……如果我尝试在 RStudio 中构建二进制文件并安装它,就会出现错误。如果我只编译源代码以获取 .tar.gz 文件,则可以正常工作,但是当我尝试安装时,仍会出现错误。以下是两次出现的错误信息。我认为这与库有关,但为什么这与我的家用电脑不同,我不知道。我不是程序员,并且在这台机器上安装 R、RTools 和 RStudio 时与在个人电脑上完全相同。- 我有几天的管理员访问权限。
install.packages("speEaR_1.0.tar.gz", repos=NULL, type="source")
Installing package(s) into ‘\\ueahome5/ressci17/yrq12edu/data/Documents/R/win-library/2.15(as ‘lib’ is unspecified)
* installing *source* package 'speEaR' ...
** R
** preparing package for lazy loading
** help
Warning: C:/Users/yrq12edu/AppData/Local/Temp/Rtmp84HJPx/R.INSTALL7e81a241d97/speEaR/man/makeSetMatrix.Rd:25: unknown macro '\begin'
Warning: C:/Users/yrq12edu/AppData/Local/Temp/Rtmp84HJPx/R.INSTALL7e81a241d97/speEaR/man/makeSetMatrix.Rd:26: unknown macro '\item'
Warning: C:/Users/yrq12edu/AppData/Local/Temp/Rtmp84HJPx/R.INSTALL7e81a241d97/speEaR/man/makeSetMatrix.Rd:30: unknown macro '\end'
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) :
  no library trees found in 'lib.loc'
Error: loading failed
Execution halted
*** arch - x64
Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) :
  no library trees found in 'lib.loc'
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing '\\ueahome5/ressci17/yrq12edu/data/Documents/R/win-library/2.15/speEaR'
Warning messages:
1: running command 'C:/PROGRA~1/R/R-215~1.2/bin/i386/R CMD INSTALL -l "\\ueahome5/ressci17/yrq12edu/data/Documents/R/win-library/2.15"   "speEaR_1.0.tar.gz"' had status 1 
2: In install.packages("speEaR_1.0.tar.gz", repos = NULL, type = "source") :
  installation of package ‘speEaR_1.0.tar.gz’ had non-zero exit status
2个回答

2

我几天前也遇到过类似的错误。这是因为你正在安装到这个目录:

 '\\ueahome5/ressci17/yrq12edu/data/Documents/R/win-library/2.15/speEaR'

我猜它连接到了一个网络驱动器。你需要做的是去那个网络驱动器,明确地复制地址,如下所示:
 'M:/ressci17/yrq12edu/data/Documents/R/win-library/2.15/'

然后在安装时使用它来指定库的位置。例如:

install.packages("speEaR_1.0.tar.gz", repos=NULL, type="source",lib='U:/ressci17/yrq12edu/data/Documents/R/win-library/2.15/')

或者尝试使用开发工具,解压你的tar包并执行如下操作:

library(devtools)
has_devel() ## check if your Rtools are properly installed
check('speEaR')
##build('speEaR')
install("speEaR",args='-l "U:/ressci17/yrq12edu/data/Documents/R/win-library/2.15/"')

这就是我解决问题的方法。

它已连接到网络驱动器。谢谢!我会在明天第一时间尝试这个解决方案! - SJWard
我刚刚尝试了使用\\ueahome5/ressci17/yrq12edu/data/Documents/R/win-library/2.15/作为R CMD BUILD INSTALL命令的-l选项,还有U:/ressci17/yrq12edu/data/Documents/R/win-library/2.15/。可惜第二个路径无法进行cd操作,因为它不存在。而第一个路径给我带来了一个与之前关于lib.loc的问题相同的问题,同时还涉及到了\\ueahome5/ressci17/yrq12edu/data/Documents/R/win-library/2.15/00LOCK-speEaR/speEaR - SJWard
@Axolotl9250,我认为你应该先将 U:/ressci17/yrq12edu/data/Documents/R/win-library/2.15/ 复制到你的Windows资源管理器中,确保你可以访问该目录。如果可以访问,那么你可以尝试使用 devtools 包。我编辑了答案并给出了一个例子。 - Zhenglei

0
我发现问题与R脚本中roxygen注释中的Windows路径反斜杠有关。解决方法是将反斜杠改为单个正斜杠。 例如:最初我的roxygen信息是这样的:
#'  Performs a search in MS Windows file system for all files in the
#'  `C:\USERS\MYNAME` directory, and all directories below that

这个会导致出现以下警告信息:

* installing to library 'C:/Users/MYNAME/Documents/R/win-library/3.2'
* installing *source* package 'whatever' ...
** R
** preparing package for lazy loading
** help
Warning: C:/Users/MYNAME/Documents/R/CODE/whatever/man/func.Rd:11: unknown macro '\USERS'
Warning: C:/Users/MYNAME/Documents/R/CODE/whatever/man/func.Rd:11: unknown macro '\MYNAME'
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (whatever)

线索是在RStudio中,文本的颜色是橙色而不是通常的蓝色。 enter image description here

因此,将反斜杠改为正斜杠,就不会产生警告消息,并且所有roxygen注释现在都是蓝色的。
#'  Performs a search in MS Windows file system for all files in the
#'  `C:/USERS/MYNAME` directory, and all directories below

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接