Handling @S3method’s Death in roxygen2 Version 4.0.0

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)

About tylerrinker

I am Literacy PhD student with a bent for the quantitative and a passion for R.
This entry was posted in package creation, qdap, Uncategorized and tagged , , , , . Bookmark the permalink.

2 Responses to Handling @S3method’s Death in roxygen2 Version 4.0.0

  1. Pingback: Handling @S3method’s Death in Roxygen 4.0.0 ← Patient 2 Earn

  2. songpants says:

    Nice post. But that’s one of the main reasons I still use the combination of Eclipse (https://www.eclipse.org/downloads/) and StatEThttp://www.walware.de/goto/statet) instead of RStudio. In Eclipse, workspace-wide find-and-replace is a piece of cake (including regular expressions) while in RStudio you are limited to specific files (AFAIK).

    I do like RStudio and I think the guys behind it doing a great job. But for heavy-duty programming Eclipse offers a lot more functionality (e.g. ability to launch multiple R processes and switch between them, a far better file explorer etc.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s