What roxygen should I put when I use a function of another package in my function

妖精的绣舞 提交于 2019-12-11 11:34:28

问题


I am writing many functions and I am trying to document using roxygen2

I use the futile.logger package a lot, say I use the flog.debug function in a function. What @* should I use to document it ?


回答1:


First, being aware of your

sessionInfo() 
getwd() # your R's working directory
.libPaths() # your R's library location

Step0 Download and install the necessary packages:

library(roxygen2)
library(devtools)
library(digest)

Step1 Put all your related ".R" files (yourfunction1.R, yourfunction2.R, yourfunction3.R) to your R's working directory.

Step2 Create your package skeleton in your R's working directory: Be sure that there is no folder named "yourpackage" in your R's working directory before running the following command. (from R's console)

package.skeleton(name = "yourpackage", code_files = c("yourfunction1.R", "yourfunction2.R", "yourfunction3.R"), path = ".")

After running package.skeleton, the folder yourpackage is created in your R's Working Directory.

Delete Read-and-delete-me file from Windows Explorer.
Delete "yourpackage-package.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder
(Do NOT delete "yourpackage.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder!)

Step3 At the end of the preamble of your ".R" file (yourfunction.R), put the following (if you had not done it so in Step1):

#' @importFrom futile.logger flog.debug
#' @export
yourfunction <- function(...) {...

Step4 In the DESCRIPTION file of your package, in the Imports part, add:

Imports:
    futile.logger(>= VersionNumber)

where VersionNumber is the version number of the futile.logger package you are using. You can find the version number by right-click any function (from yourpackage) in Object Browser of RevolutionREnterprise; and going the bottom of the resultant .html help file. There, the version number of the package is shown.

In Step2, package.skeleton automatically produced a NAMESPACE file whose content is:

exportPattern("^[[:alpha:]]+")

Do not handle this NAMESPACE file manually.

Step5 roxygenize the package you wanna create ("yourpackage")

library(roxygen2)
roxygenize("yourpackage")

Upon roxygenization, the content of the NAMESPACE file of yourpackage is automatically converted from exportPattern("^[[:alpha:]]+") to

# Generated by roxygen2: do not edit by hand

export(yourfunction)
importFrom(futile.logger,flog.debug)

Step6 Build your package:
(first, delete "src-i386" and "src-x64" folders (if any) in YourR'sWorkingDirectoryFolder\yourpackage folder from Windows Explorer)
(Be sure again that there is no "yourpackage-package.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder. If there is, delete it before building)

build("yourpackage")

Step7 Install your package:

install("yourpackage")

Step8 Check that all is going well by loading your package and running a function in the package.

library(yourpackage)
yourfunction(6,1,2) # "yourfunction" is a function in the package "yourpackage"

Step9 Check that your package is loadable to CRAN (Comprehensive R Archieve Network) (if you wanna share your package):

(first, delete "src-i386" and "src-x64" folders (if any) in YourR'sWorkingDirectoryFolder\yourpackage folder from Windows Explorer)
(Be sure again that there is no "yourpackage-package.Rd" file in YourR'sWorkingDirectory\yourpackage\man folder. If there is, delete it before checking)

From DOS Command Prompt:
Start – cmd - Enter. Pass to R's working directory (your R's working directory is known via getwd()) and do CRAN check:

cd C:\Users\User\Documents\Revolution
R CMD check yourpackage

From R's console:

devtools::check("C:/Users/User/Documents/Revolution/yourpackage")


来源:https://stackoverflow.com/questions/37111471/what-roxygen-should-i-put-when-i-use-a-function-of-another-package-in-my-functio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!