qosahalo.blogg.se

Build r package
Build r package







build r package

That gives you some scaffolding to document the function in a way that R understands, such as #' Title #' #' day #' #' #' #' #' Title field is pretty self-explanatory, and you can also add a line for a short description. Put your cursor anywhere in the function definition and choose the RStudio menu option Code > Insert Roxygen Skeleton. Roxygen offers an easy way to add documentation to a function. You can name the file anything you want, and you can include one or more functions in the file. Next, write any function as usual, and save it as an R script in the R directory. You can see how this automatically adds the necessary text to the DESCRIPTION file in the video embedded at the top of this article (or by running similar code on your own system). For example, if you need the lubridate package for your package, you can load usethis with library(usethis) and then run use_package("lubridate") to add a dependency.

build r package

The usethis package can handle proper package-dependency format for you. It’s mostly easy things like the package name, author, description, and license.

build r package

Explaining NAMESPACE could be an article in itself, but beginners can count on the devtools and usethis packages taking care of that.ĭESCRIPTION has some important required metadata about the package, so you need to fill that out. There are also a couple of important files in the main directory. RStudio also creates a sample hello.R R function. The man folder is for documentation-specifically, function help files. The R subdirectory is where all my R scripts need to live. At the bottom right panel after creating the package, note that a few files and two directories were created.









Build r package