R custom package install from file error

2019-02-24 19:56发布

问题:

I've been working on a R package for a simulation project, on my computer at home I've used RStudio to build and install it successfully. However on another machine at university I'm having trouble... If I try and build a binary in RStudio, which also installs it too, I get an error, If I just compile a source to get a .tar.gz it works, but then when I come to install I get the error again. The readout with error that occurs both times, is below. I think it has something to do with libraries, but why this would be different to my home computer I would not know, I'm no programmer, and installed R and RTools and RStudio in exactly the same way on this machine as on my personal machine. - I have admin access for a few days.

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

回答1:

I had encountered a similar error a few days ago. It is because you are installing to this directory:

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

I guess it is connected to a network drive. What you should do is go to that network drive and copy the address explicitly like

 'M:/ressci17/yrq12edu/data/Documents/R/win-library/2.15/'

And then use it to specify the library location when you install. For example:

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

Or try devtools , unpack your tar ball and do something like:

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/"')

This is how I solved my problem.



回答2:

I found the problem was related to the Windows path backslashes in the roxygen comments in the R script. The solution is to change the backslashes to a single forward slash. Example: originally my roxygen info was like this:

#'  Performs a search in MS Windows file system for all files in the
#'  `C:\USERS\MYNAME` directory, and all directories below that

which results in this warning message:

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

The clue is that the text is orange instead of the usual blue in RStudio.

So change the backslash to a forward slash and no warning message is produced and all the roxygen comment is now blue.

#'  Performs a search in MS Windows file system for all files in the
#'  `C:/USERS/MYNAME` directory, and all directories below