What does “Error in namespaceExport(ns, exports) : undefined exports” mean?

后端 未结 4 1862
时光取名叫无心
时光取名叫无心 2021-01-03 20:38

When building a package, I got the error

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

What does this mean, and h

4条回答
  •  臣服心动
    2021-01-03 20:46

    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.

提交回复
热议问题