
Much of the ease of installing R its add-on packages is thanks to the CRAN infrastructure. In addition, installing packages in R can be considerably simpler than in other languages. Both R the language and the thousands of published packages which extend its functionality for the most part work across the three platforms. R has very good support on the three main platforms: Linux, MacOS, and Windows. C.6.1 Iteration with functional programming.

A.2.1 Installing R on a Mac via Homebrew.1.5 Why use a programming language for historical data analysis?.1.4 How to learn computational historical thinking.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().

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). 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) Use_r("my_func_with_ dplyr") #creates 'R/my_func_with_dplyr.R' Use_package("dplyr") #adds "dplyr" to Imports field in DESCRIPTION
