Handling @S3method’s Death in Roxygen 4.0.0

May 11, 2014

(This article was first published on TRinker's R Blog » R, and kindly contributed to R-bloggers)

This is a quickie post and specific to package maintainers who use roxygen2.

Legal Disclaimer: This worked for me but make sure there’s not a corner case that would make it not work for you.  In other words back your stuff up think it through, and tread lightly.

Welp I updated to the latest version of roxygen2, 4.0.0. Works well and some new niceties and handling. Anyway after you use it for the first time and if you have @S3method in your code it throws a warning along the lines of:

Warning messages:
@S3method is deprecated. Please use @export instead

Inconvenient to make the change if you have a small amount of functions in your package but a pain in the tush if you have tons. Obviously you’ll want to do this as @S3method is deprecated but it doesn’t make it hurt any less. It’s kinda like a a root canal, it’s for the good of the dental well being but it’s still painful. But then a thought occurred to me. Why not be lazy efficient? Read in the files, grepl to find the "#' @S3" and then replace with "#' @export". I tried it with the following code. You’ll have to supply your path to the location of the package’s R directory.

Now this may not be the best approach, hey it may even be wrong but I’ll rely on Cunningham’s Law to sort it out:

pth <- "C:/Users/trinker/qdap/R"

fls <- file.path(pth, dir(pth))

FUN <- function(x) {
    cont <- readLines(x)
    cont[grepl("#' @S3", cont)] <- "#' @export"
    cont[length(cont) + 1] <- ""
    cat(paste(cont, collapse="\n"), file=x)

lapply(fls, FUN)

To leave a comment for the author, please follow the link and comment on their blog: TRinker's R Blog » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)