What does "Error in namespaceExport(ns, exports) : undefined exports" mean?
Asked Answered
B

5

26

When building a package, I got the error

Error in namespaceExport(ns, exports) : 
  undefined exports: FooBarBaz

What does this mean, and how do I fix it?

Blockbuster answered 2/11, 2014 at 9:9 Comment(0)
B
13

This error occurs when you try to export an object that doesn't exist. That is, the package NAMESPACE file contains the line

export(FooBarBaz)

but FooBarBaz doesn't exist in the package.


One case where this error can occur is when you are trying to create a common help page for several functions using roxygen2. In the example below, f and g are related functions to be documented in the WidgetUtils page.

#' Widget-related functions
#' 
#' Utility functions to assist working with widgets.
#' @param x An input.
#' @return A value.
#' @name WidgetUtils
#' @export
NULL

#' @rdname WidgetUtils
#' @export
f <- function(x)
{
  x + 1
}

#' @rdname WidgetUtils
#' @export
g <- function(x)
{
  x - 1
}

The mistake in this code chunk is the inclusion of the @export tag in the WidgetUtils roxygen block. This tells roxygen to generate the export line in the NAMESPACE file, but its value is NULL, so there is nothing to export. By removing the @export line, so the code will work correctly.

Blockbuster answered 2/11, 2014 at 9:9 Comment(2)
This dind't help me outMohr
@MarcinKosiński If this answer doesn't fit your needs, then either 1) Work out what has gone wrong in your case and update the answer (it's a community wiki, so feel free to edit), or 2) Ask a new question describing your problem, and including a minimal reproducible example. Otherwise you're just trolling.Blockbuster
I
7

Be careful not to have any commented lines that begin with an apostrophe!

By bad luck, inside my function I had commented out a line that began with an apostrophe (in front of 'Battlestar Galactica' in my fake example) so it look like this:

#' @export
getMyFavoriteSciFiShows <- function() {
  myFavoriteSciFiShows <-
    c('Star Trek Next Generation',
      #'Battlestar Galactica',
      'Babylon 5')
  return(myFavoriteSciFiShows)
}

This really screwed up roxygen2 v 6.0.1 since it did not signal any errors and this is what it put into my NAMSEPACE file:

export("Galactica',")
export(Battlestar)

Not only was my desired export myFavoriteSciFiShows missing but two erroneous ones were added. These erroneous ones can result in undefined exports.

Involved answered 22/2, 2017 at 16:24 Comment(4)
Can you provide an example of when #' @export fails?Blockbuster
@RichieCotton \@export can fail if the function contains a commented line that begins with an apostrophe.Involved
@RichieCotton I replaced my entire answer in response to your question once I figured out why my export was having trouble. Thanks!Involved
It is a good idea to use hash + space for comments. CTRL+SHIFT+C (CMD+SHIFT+C on macOS) does this in RStudio.Blockbuster
H
4

I had a very stupid typo: in roxygen2 skeleton, I copied what was meant to go into #' @return field, to @export.

Should have been:

#' @return new data frame
#' @export

Instead, I had:

#' @return
#' @export new data frame
Haemal answered 30/4, 2018 at 13:59 Comment(0)
R
1

I removed a function, and roxygen2 didn't seem to remove it from the NAMESPACE file. Go in there and delete that line manually and it will fix the error

Radioman answered 25/5, 2019 at 18:16 Comment(0)
P
-1

There has alternative way, download package from GitHub repo, and then Install & Restart

Pomander answered 4/6, 2021 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.