1

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"
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • what does `ls(getNamespace('saber'))` return; whats in the namespace file? – rawr Jul 26 '14 at 00:03
  • `character(0)` is the return. The file is two imports and 19 exports. Do I need to install it to one of `.libPaths()` maybe? – Rich Scriven Jul 26 '14 at 00:06
  • hm, not sure. It's weird that none of your exports are showing up. does it work if you install it from github? – rawr Jul 26 '14 at 00:16
  • That's a separate issue. I don't really know how to put it on GitHub without losing my mind. I wrote the package, it's my first one and I'm still learning the ropes. I thought I had [this problem](http://stackoverflow.com/questions/24944387/errors-when-using-rstudios-git-tools) figured out, but today I opened RStudio and it was reverted back to the problem. – Rich Scriven Jul 26 '14 at 00:17
  • Can you look at the NAMESPACE file **in the package**? Maybe you are generating the NAMESPACE file via `roxygen2`, and it creates an empty file, because you don't have `@export` roxygen flags? It would actually help if you could upload the package tarball (or something minimal if it is private) somewhere, so that we can actually look at it. – Gabor Csardi Jul 26 '14 at 01:51
  • Sorry, I was wondering about why the functions are not exported, not about github. For uploading the package, just take the built tarball and upload it to dropbox or even as a github gist if it is not too big. I don't use rstudio, so I can't help you with using git from rstudio. But I bet that the NAMESPACE file in the package is empty. In the built/installed package. – Gabor Csardi Jul 26 '14 at 02:23
  • Or even just create a gist and upload one R source file from your package and the code that you use for building it. Or maybe you build it from rstudio. – Gabor Csardi Jul 26 '14 at 02:24
  • @GaborCsardi - I put three files at [this gist](https://gist.github.com/rmscriven/abd7464f686540c507b8) – Rich Scriven Jul 26 '14 at 02:49
  • Can you include DESCRIPTION as well? – Gabor Csardi Jul 26 '14 at 02:55
  • And your saber.Rproj file? This is the last one, I promise.... – Gabor Csardi Jul 26 '14 at 03:17
  • How can I view the contents of that file? – Rich Scriven Jul 26 '14 at 03:18
  • It is a text file. Any text editor is fine. – Gabor Csardi Jul 26 '14 at 03:19
  • Okie doke. It's up there too – Rich Scriven Jul 26 '14 at 03:22
  • OK, I think I can replicate this. Wait a minute. – Gabor Csardi Jul 26 '14 at 03:28

1 Answers1

1

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. E.g. 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.

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
  • Thank you sir! Like I said, rookie mistake and a minor one at that. The reason I chose `load_all()` is because I usually see a `package intalled to filepath` message after an install but not when I did this install. Definitely knowledge for the next run. Cheers. – Rich Scriven Jul 26 '14 at 04:43