Exporting non-S3-methods with dots in the name using roxygen2 v4
As Mr Flick commented, appending the full function name to the roxygen line works correctly. If I change the line to:
#' @export check.arg
then the NAMESPACE
file contains:
export(check.arg)
roxygen2: Issue with exporting print method
I have found a solution for my problem (In comments above) and it may work for yours. In The NEWS.md file for v3.0.0, it is mentioned that @method
tag is not needed as roxygen2 will figure it out, but it's sill available in the rare case that roxygen2 cannot do so. My solution:
#' @method print myClass
#' @export
print.myClass <- function(x) print("myClass")
This gives me back the S3method(print, myClass)
in my NAMESPACE file.
S3 method help (roxygen2)
The bug you are seeing is mostly likely caused because the list method of the common generic is not being exported, so common.default
gets called instead. You can pick up this problem using devtools::missing_s3
- the function is a bit heuristic, so you may get a few false positives (e.g. it can't currently tell that is.list
isn't a method). This is an incredibly common problem (it has caught me so many times), and the next iteration of roxygen will do more to prevent it.
Currently, to correctly export S3 methods with roxygen you need to do either:
@S3method generic class
(and nothing else) if you don't want to document the method@method generic class
and@export
if you want to export and document it.
You should never have @S3method
and @method
in the same documentation block.
Update for roxygen2 >3.0.0
Now roxygen automatically figures out if a function is an S3 method so:
- Never use
@S3method
or@method
- Use
@export
if you want the method to be exported (which you normally do, even if the generic isn't)
R package documentation: Found the following apparent S3 methods exported but not registered
I don't know Roxygen2
very well, but it appears that you have declared is.nan.data.frame
to be the is.nan
method for class data.frame
. Since you did that, you should call it as is.nan(df)
in the help page example.
If you don't want it to be the method, you just want it to be a regular function using dots in the name, then you shouldn't have @method is.nan data.frame
. But you indicate that you do want it to be a method.
Edited to add: Just to summarize your comments, the following fixes got rid of all the errors:
- use @export by itself without naming the function (as suggested by @KonradRudolph)
- remove the @usage line
- use
is.nan(df)
in the example (as I suggested)
Roxygen thinks a function of mine is an S3 method, and so breaks upon installation of my package
Fixed it!
Using @export extract.sig.metadata
instead of @export
apparently tells roxygen that extract.sig.metadata is the entire function name, and this fixes the problem. In this particular case, I didn't have a generic extract function, but R.utils (a package that my package did not depend upon but was nevertheless loaded) did have an extract function.
Hope this helps anyone with the same problem in the future. Thanks!
P.S. Hadley suggests better naming practices, which I will attempt to follow in the future.
Exporting data in Roxygen2 so that they are available without requiring data()
In the DESCRIPTION
file of your package make sure that there is a field called LazyData
that is set to TRUE
.
From the "Writing R Extensions" guide:
The ‘data’ subdirectory is for data files, either to be made available
via lazy-loading or for loading using data(). (The choice is made by
the ‘LazyData’ field in the ‘DESCRIPTION’ file: the default is not to
do so.)
I think the exact syntax changed with R version 2.14; before that it was LazyLoad not LazyData.
Related Topics
How to Determine If Date Is a Weekend or Not (Not Using Lubridate)
Normalizing Y-Axis in Histograms in R Ggplot to Proportion
Ggplot2 Multiple Scales/Legends Per Aesthetic, Revisited
How to Apply Cross-Hatching to a Polygon Using the Grid Graphical System
Counting the Frequency of an Element in a Data Frame
Inputting Na Where There Are Missing Values When Scraping with Rvest
Two-Column Layouts in Rstudio Presentations/Slidify/Pandoc
Create an Id (Row Number) Column
Automatically Adjust Latex Table Width to Fit PDF Using Knitr and Rstudio
R: Replace Multiple Values in Multiple Columns of Dataframes with Na
How to Coerce a List Object to Type 'Double'
How to Maintain Size of Ggplot with Long Labels
Add a Column with Count of Nas and Mean
Merge Panel Data to Get Balanced Panel Data
Combine Several Data Frames in the Global Environment by Row (Rbind)
Greek Letters, Symbols, and Line Breaks Inside a Ggplot Legend Label