简体   繁体   中英

Trouble installing a source package from a local file

This seems like it might be a rookie mistake because it probably is. I have a built source package that I'm trying to install. It's a local file and I just want to check to make sure it works. Everything seems to go smoothly, no errors...but also no functions.

> dir.create("packageCheck")
> install.packages("Rpackages/saber_0.1.tar.gz",   
                   lib = "packageCheck", repos = NULL)
# * installing *source* package ‘saber’ ...
# ** R
# ** inst
# ** preparing package for lazy loading
# ** help
# *** installing help indices
# ** building package indices
# ** testing if installed package can be loaded
# * DONE (saber)
> list.files("packageCheck")
# [1] "saber"
> list.files("packageCheck/saber")
# [1] "DESCRIPTION" "extdata"     "help"        "html"       
# [5] "INDEX"       "Meta"        "NAMESPACE"   "R"          
> devtools::load_all("packageCheck/saber")
# Loading saber
> library("saber", lib.loc = "packageCheck/saber", logical.return = TRUE)
# [1] TRUE
> ls(2)
# character(0)
> ls("package:saber")
# character(0)

What am I doing wrong here?

Note:

> version[[1]]
# [1] "x86_64-pc-linux-gnu"
> getOption("pkgType")
# [1] "source"

The problem is that devtools::load_all() is not for loading installed packages. It is meant to be used in the source tree of your package. Eg if you just say load_all() in the source tree of your package, then it should work.

What I guess happens, is that load_all() looks for .R files to load in the installed package, but there are no .R files in installed packages, the R functions are put in a database when you install a package:

/tmp/saber (master)$ ls -l packageCheck/saber/R/
total 24
-rw-r--r--  1 gaborcsardi  wheel  1056 Jul 25 23:27 saber
-rw-r--r--  1 gaborcsardi  wheel  3317 Jul 25 23:27 saber.rdb
-rw-r--r--  1 gaborcsardi  wheel   246 Jul 25 23:27 saber.rdx

So load_all() does not find anything to load, but it creates a namespace nevertheless, named saber . Then, when you try to load the package with library() , the function returns immediately, because it notices that there is a saber namespace in the search() list, so it assumes that the package was already loaded.

The solution is either to

  1. just use load_all() and then reload() in the source directory of your package, without actually installing it. (You might need to build, I am not sure about that.) This works most of the time.
  2. Or just use library to load the installed package:

    library("saber", lib.loc = "packageCheck", logical.return = TRUE)

    This is somewhat less convenient, because you need to build and install all the time and unloading/reloading a package might fail in R.

Just don't use load_all() on the installed package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM