Roxygen2 generates documentation of the function from these comments. The first is the Roxygen comment section, of which each line starts with #'. R file, let’s call it mess_up_function.R, has two sections, as shown in the example code below. We can have as many files as needed for all functions under subdirectory /R. A good practice is to have only one function in a. R files for a function and save it in subdirectory /R. I try to make this one to be the simplest and most up to date.Ĭreate a. There are many great tutorials for building R packages. If this package is just for ourselves, we can save the hassle of publishing it on github or CRAN.īelow are step by step instructions of building a working package in RStudio. In RStudio, it is nothing but writing normal R code with formatted comments. With the help of package documentation, these functions and datasets become our great asset.īuilding a R packages is actually far more easier than a R user could have expected. By building functions and datasets into a package, we keep them in one place and use them the same way as using any other packages. We will have to know where the functions and datasets are stored, which is not a easy job if we have a large collection. The conventional way to reuse functions is to copy and paste them to the new project or to load them by source(xxx.R), and the conventional way to reuse datasets it to load. As a R user, we must have written functions and collected datasets, and may have used them across projects or may want to use them later on. Developers write packages for others we can just write packages for ourselves. We don’t have to a be R developer to write packages. I have read people writing about the benefit in various occasions and cannot agree more after building my first package. A R user can benefit a lot from building packages.
0 Comments
Leave a Reply. |