Building R Package Error: Objects listed as exports, but not present in namespace
Asked Answered
D

4

21

I am building R package. Recently, I deleted and renamed several functions in R/allFunctions.R. I had previously been able to automatically update NAMESPACE, but for some reason, I am not able to now, and get some errors as follows:

library(packageName)
library(roxygen2)
library(devtools)
install()
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/packageName’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/packageName’
Error: Command failed (1)
document()
Updating packageName documentation
Loading packageName
Warning message:
In setup_ns_exports(pkg, export_all) :
  Objects listed as exports, but not present in namespace: functionOne, functionTwo

I see that clearly I have some objects that are not present in namespace that are listed as exports. However, I removed all @export in the allFunctions.R file. I see in NAMESPACE that some newly named function names are not there, and that some old (since renamed) function names are still there. I could change it by hand, but I know that is dangerous, and want to avoid those poor techniques.

If you have any ideas, please let me know! Thank you.

Davena answered 26/10, 2014 at 16:23 Comment(5)
Thank you @RichardScriven. I tried build("../packageName"), and got the following error:Davena
Error in namespaceExport(ns, exports) : undefined exports: functionOne, functionTwo Error: loading failed Execution halted ERROR: loading failed * removing ‘/private/var/folders/vn/lhzbs8ds6xbg965nnfcj6ftm0000gn/T/RtmpK8kfl1/Rinst839556135808/packageName’ ----------------------------------- ERROR: package installation failed Error: Command failed (1)Davena
delete the namespace file and let roxygen make itFichte
@Fichte Is it agreed that I may have to make the NAMESPACE file by hand then? I believe I am in the "viscious cycle" mentioned here (github.com/klutometis/roxygen/issues/229). Because, when I did delete the NAMESPACE file and run build() and document(), both gave me an error "ERROR: a 'NAMESPACE' file is required". I just want to make sure making NAMESPACE by hand is the only option since it seems kind of inefficient and unsafe.Davena
I wouldn't think so. It looks like there are only two functions causing inconsistencies in the objects that you @export vs lines in your NAMESPACE. Can you go through line by line and make sure they match up? Did you spell everything correctly and make all the name changes everywhere? Are you using @export or @export functionOne? The error is telling you exactly which ones arent meshing. Also, have you considered using Rstudio to organize your package and build?Fichte
A
22

@jtr13's Answer worked for me as well. Just run devtools::document() a second time and the warning goes away.

> devtools::document()
Updating pavm documentation
Loading pavm
Writing NAMESPACE
Deleting evlCalcTime.Rd
Deleting initTimeStamp.Rd
Warning message:
In setup_ns_exports(pkg, export_all) :
Objects listed as exports, but not present in namespace: evlCalcTime, 
initTimeStamp

> devtools::document()
Updating pavm documentation
Loading pavm
Alanaalanah answered 24/4, 2018 at 23:9 Comment(0)
G
3

I just did a similar thing: I deleted 3 exported functions from R/allFunctions.R and ran devtools::document(). This gave me the following error:

Warning message:
In setup_ns_exports(pkg, export_all) :
  Objects listed as exports, but not present in namespace: getAccounts, getClients, getDeposits

I solved the problem by manually deleting the 3 export() functions from the NAMESPACE file.

Glasswort answered 19/12, 2015 at 4:54 Comment(2)
I believe that although you get the warning message, devtools::document() does clear up the problem. I deleted a function, ran devtoools::document(), got that warning, ran devtools::document() again, no more warning.Uda
@Uda I believe the answer is in the comment; I would not recommend manually editing NAMESPACE (!!)Pipsissewa
P
1

In my experience, this is often a typo-mismatch between function definition and roxygen statement, especially when camelCase notation is involved, for example:

#' @export functionOne
functionone <- function() { ... }
Precaution answered 12/4, 2018 at 12:17 Comment(0)
U
0

This is an old question, but for anyone finding it: this error can be generated by using a double assignment arrow (<<-) instead of the standard arrow (<-) in the function definition (at least with devtools 2.4.5 and roxygen2 7.3.1)

Unhouse answered 26/4 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.