If you accidentially did both, remove the global version using rm(concat_two_vec). Do not use both methods mentioned above in the same time, this will create concat_two_vec() in the global space and mask myfirstRpackage::concat_two_vec(). You can use various functions from the lubridate package in R to convert a character column to a date format. Calling source("R/concat_two_vec.R") in package root directory will install it in the global workplace, whereas load_all() installs this package in development mode (also installs unexported internal ones, read more in devtools). The process of creating a usable package in R has several parts: Write the function (s) to include in the package. Install package functions in dev mode and do some testsĪfter you’ve written a function and would like to test if it works, there are two ways to make a function available. Use git to commit small and meaningful changes, you can use git window built in Rstudio to do that. Each time you add a new function to R/, you will need to run document() again. The documentation will be saved in man/ and can be looked up by ?function_name.In addition, it adds function names in R/ to NAMESPACE. There are many more types of tags one can use, see roxygen quick reference.Īfter docstring of the function of interest is generated, run document() to generate documentation for the functions you have in R/. Most functions’ docstring have (follows by the description of input, one input variable per line), (follow by the description of what the function returns), (follows by an example usage of the function). To do this, we would need to write docstrings in a specific way for each function before defining it. Here we want to use roxygen2 package to generate markdown page for each function, the markdown files will be saved in man and can be accessed by ?function_name. Use_test() # create unit test template, you can add some test cases My_func_with_dplyr <- function(df, col_name) testthat - testthat provides an easy way to write unit tests for your code. devtools - An essential suite of tools for turning your code into an R package. httr - A set of useful tools for working with http connections. jsonlite - Read and create JSON data tables with R. Use_r("my_func_with_ dplyr") #creates 'R/my_func_with_dplyr.R' XML - Read and create XML documents with R. Use_package("dplyr") #adds "dplyr" to Imports field in DESCRIPTION
0 Comments
Leave a Reply. |