[R] Need import S3 functions for a package to use

[This article was first published on R on Zhenguo Zhang's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Zhenguo Zhang’s Blog /2023/01/20/r-need-import-s3-functions-for-a-package-to-use/ –

When developing an R package, it has been suggested to just put the dependent packages in Description file under Imports section.

However, I recently found that for S3 methods exported by a package, one need to import such functions explicitly in order to use them in the developed package. One example is the unique() function from the package data.table. This function can’t be called via data.table::unique(), because it is a S3 method. However, if it is not imported, the method uniq.data.frame() would be used instead.

To import it, one can add the following roxygen2 comment above the calling function:

1
#' @importFrom data.table unique

Then run devtools::document() to update relevant files, including NAMESPACE.

This is just a quick note in case similar problems are met in future.

😄

Happy Chinese Lunar New Year!

– /2023/01/20/r-need-import-s3-functions-for-a-package-to-use/ –
To leave a comment for the author, please follow the link and comment on their blog: R on Zhenguo Zhang's Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)