3

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 and myPackage::somefunction 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...
Writing NAMESPACE
Warnmeldung:
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 NAMESPACE 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) NAMESPACE contains exportPattern("^[[:alpha:]]+").

Trying to repair this (and editing the file by hand) I copy this line to NAMESPACE 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, NAMESPACE 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

Phann
  • 1,283
  • 16
  • 25
  • I found this answer here which explained a few things to me: http://stackoverflow.com/questions/23869956/error-when-building-r-package-using-roxygen2?rq=1 and I managed to get it working again by disabling roxygen -> Options -> generate NAMESPACE file. But why this behaviour has changed is still not clear. – Phann May 04 '16 at 09:23

3 Answers3

11

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.

Collin
  • 326
  • 2
  • 6
  • 1
    Thank you! Please correct the link, you have a dot inside the link behind 'html'. This explains why roxygen2 isn't correctly creating the NAMESPACE. – Phann May 25 '16 at 09:08
  • Thank you, works perfectly! I've been looking all over for a solution but nothing worked until I came across your solution. – Christian Dec 06 '18 at 20:45
0

Maybe completely unreleated, but I had the exact same issue, and it seemed that I had the incorrect stuff in my .Rbuildignore file. Actually, it was because I had blank lines in there.

- frbl

frbl
  • 1,172
  • 11
  • 17
0

I had the same problem. I copied somewhere an example #' @export and it didn't work.

Later I tried other " ' " and at last i found: #' @export works.

lrnzcig
  • 3,868
  • 4
  • 36
  • 50
Rüdiger Kladt
  • 119
  • 1
  • 7