labroker.blogg.se

Making a package in r
Making a package in r






making a package in r

RD file is what’s used to create the actual help file. (As usual, R allows for either the American English or British English version of the command, so roxygenise() works just as well.) Once you’ve finished adding the roxygen comments, run the following command: roxygenize() Double-check these examples before finishing, to make sure no errors crept in while you weren’t looking. Use the plural if you’re adding more than one line of examples. Example/Examples - Add one or more lines of examples.Return - What the function will give you.Param - Add one of these lines for each parameter to your function.Description - used to add a short description.There are several items that you should add: #' #' #' #' #' #' Title - used to add a title to the help page (use title case) Now, we go to the R script and add some roxygen comments to the beginning. install.packages("roxygen2") library(roxygen2) The easiest way to create a help file is to use the roxygen2 package. I stored this function in a script called sortby.R. The first step is covered above with my sortby() function. (Optional, and not covered here) Publish the package.Create the documentation for the function(s) in the package.Write the function(s) to include in the package.

making a package in r

The process of creating a usable package in R has several parts: While none of the tutorials actually exclude the use of RStudio, many of them ignore it altogether. One of my requirements, then, is that it must be doable within that environment. The purpose of this article is to detail, from start to finish, the process I came up with by combining many of those tutorials.įirst, I should mention that I use RStudio for all of my R programming.

making a package in r

Some were incomplete or broken up into multiple pages. Now, there are a lot of tutorials out there on how to create R packages, but they all lacked something. The answer was to create my very own package. The problem I had then was how to find the function when I want to use it. Here’s the latest version of the function that I came up with: sortby <- function(df, col, desc = FALSE) Finally, I decided to create an easy-to-use function that could sort data frames for me. Every time I want to sort a data frame, I have to puzzle through how to do it, usually by looking up online how somebody else did it, then copying and modifying their code. I don’t know about you, but I find the method that R uses to sort data frames incredibly non-intuitive.








Making a package in r