Phann Phann - 25 days ago 4x
R Question

Building own package but namespace is empty after loading

I'm using RStudio to create own packages, which has worked well so far. When I build a package now by 'Build Source Package' of RStudio (to move the package from my Windows machine to a Linux machine) everything seems fine. I install the package on the Linux machine, load it with require (or library), but no function can be found! The error is

object 'somefunction' not found
says that no such object is exported. Indeed if I have a look at the environment of myPackage in RStudio it shows that it is empty.

RStudio says by creation:

==> roxygen2::roxygenize('.', roclets=c('rd', 'collate', 'namespace', 'vignette'))

First time using roxygen2. Upgrading automatically...
Paket 'nlme' wurde unter R Version 3.2.5 erstellt
Documentation completed

==> Rcmd.exe build myPackage

* checking for file 'myPackage/DESCRIPTION' ... OK
* preparing 'myPackage':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
Removed empty directory 'myPackage/data'
* building 'myPackage_2.0.0.tar.gz'

Source package written to D:/Code

I found out the the file
of my project just contains the line
# Generated by roxygen2: do not edit by hand
. In my other packages (build earlier and not rebuild for the moment)

Trying to repair this (and editing the file by hand) I copy this line to
of 'myPackage'. If I now do 'Build & Reload' in RStudio it installs the package locally and finds all functions as desired.

==> Rcmd.exe INSTALL --no-multiarch --with-keep.source myPackage

* installing to library 'C:/Users/user/Documents/R/win-library/3.2'
* installing *source* package 'myPackage' ...
** libs
make: Nothing to be done for `all'.
installing to C:/Users/user/Documents/R/win-library/3.2/myPackage/libs/x64
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (myPackage)

BUT when I now do 'Build Source Package' in RStudio,
is again modified just to the comment and the same problem occurs again.
So I don't know how to create the package as source package.

Versions: R version 3.2.4 Revised (all packages up-to-date meaning roxygen2_5.0.1), RStudio 0.99.896


I had the same problem trying to create a package. I got it to work by adding #' @export before each function, as explained on here.

The @export line is critical. This tells Roxygen2 to add this function to the NAMESPACE file, so that it will be accessible to users. For your first R package, you’ll probably want to include @export for each of your functions.