11/19/2023 0 Comments Create r packageHowever, instead of doing this manually, we can use the function named create_package in the usethis package to do these routine steps for us.įor example, to create an R package called rdemopkg inside your current R working directory, you would do the following: usethis::create_package('rdemopkg')Īlternatively, if you want to put the rdemopkg directory in an already existing directory named code/ inside your home directory, you would do the following: usethis::create_package('~/code/rdemopkg')īy default, when working in RStudio, create_package will create the R package skeleton and also make that directory an RStudio project, and also open up the RStudio project in a new RStudio session. We could therefore create an R package initially by manually creating a directory, adding sub-directories of particular names, adding blank files for the meta information files, adding blank R code files, etc. It is not always quite as simple as that, but that is the basic general structure. Some tidyverse code is used in some examples, but using tidyverse is optional.Īn R package is essentially just a directory (folder) with some meta information files, sub-directories with specific names like R/ and data/ etc, and inside these sub-directories, there are files with R code or data files. The only packages that are required to follow this guide step by step are usethis, fs (for viewing the file tree in the package), and pkgdown. The demo R package that is made here is now available on GitHub, and its pkgdown website is available on github.io. I’ve broken this guide into a series of 11 consecutive steps (from step 0 to step 10), beginning with the creation of a bare-bones R package skeleton, and ending with publicly hosting the package on GitHub, from which it can then be installed by anyone. This post provides a guide to building a small R package, but one with almost all the key features of any R package. The key steps involved in creating an R package are not difficult to learn, and they are often made even easier with tools provided by packages like usethis or devtools, and by tools in the RStudio IDE. Creating an R package is the best way to organize, document, and distribute your R code and its accompanying data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |