BorisD
BorisD

Reputation: 35

R package creation function names and .R/.rd name

Does the name of the .R and .rd files (documentation) need to have the exact same name as the function it refers to?

For example, can I have a function called "b" and another one called "B" within the same R package and write the documentation into different .R and .rd files?

I'm a bit confused and I wasn't able to find someone encountering the same problem (I even looked it up on DataCamp's course), so thanks in advance.

Best regards!

Upvotes: 2

Views: 74

Answers (1)

Waldi
Waldi

Reputation: 41220

As the .R file can contain many functions, it doesn't need to have the same exact name as the function(s) it refers to.

Regarding the .Rd files, it's much easier/efficient/practical to let Roxygen turn specially formatted comments into .Rd files.

On Windows (files not case sensitive) avoid to use Upper case / lower case to distinguish functions, because the .Rd file of one of the functions will be overwritten:

Updating package documentation
Loading package
Writing NAMESPACE
Writing FOO.Rd
Writing foo.Rd
#' foo
#'
#' A function to print bar
#'
#' @param bar 
#'
#' @return prints input
#' @export
#'
#' @examples
#' foo(1)
#' 
foo <- function(bar) { print(bar) }

#' FOO
#'
#' Another function to print bar
#'
#' @param bar 
#'
#' @return prints input
#' @export
#'
#' @examples
#' foo(1)
#' 
FOO <- function(bar) { print(bar) }

?foo

enter image description here

Upvotes: 3

Related Questions