I am writing an R package and in the following link,
How can I load dependencies in an R package? a response indicates that it is necessary to "add a line in your NAMESPACE file importFrom(ncdf4, nc_open) and then in your code, call the function without the package: nc_open(...)"
and here, How to properly include dependencies in R-package? an user says:
"The NAMESPACE file. Here you declare the packages you need
import(ggplot2) or to avoid namespace clashes
importFrom(ggplot2, geom_point) You can get roxygen2 to maintain the NAMESPACE file using the @import and @importFrom tags."
These recommendations look straightforward. However, as I create NAMESPACE with the r package roxygen2, the file NAMESPACE cannot be edited manually.
Then, how to edit the file NAMESPACE?
Very much thank you in advance
If you need full example, this is how it could look:
#' Title
#'
#' @return
#' @export
#' @import ggplot2
#' @importFrom data.table setDT
#' @examples
my_function <- function() {
}
To insert roxygen2 skeleton - go to "Code" tab in RStudio and search Insert Roxygen Skeleton.
tag @export indicates that my_function will be exported to be visible for users, when using package::my_fun or after library(package). Tag @import makes all exported functions from ggplot2 package available for you, i.e. no need to use ggplot2::aes() when you use functions from this package in your package. Tag @importFrom makes available only explicitly mentioned function from package, i.e. no need to use package::fun(), but it will be necessary for other functions from this package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With