knitr::opts_chunk$set(echo = TRUE)

Create a project

Go to the \code{file} menu and create a project. If you already have a project in github, select the \code{Version Control} option. If this is a new project, select \code{New directory} and then \code{R package}

Now load the following libraries

library(devtools)
library(roxygen2)
library(usethis)

After creating the package, you will have a \code{hello} function and you can select \code{install and restart} from the \code{Build} menu and R will build your package.

Write your own functions

To write each function, use the following code. It will create an R file and you can edit that. If you don't want to use the package \code{usethis}, you can create an R file inside the R folder in the project folder.

usethis::use_r("My_function")

Wirte the first function and then use git to have more control over your project. with \code{use_git} you can initiate git for your project. Now you need to restart RStudio to the \code{Git} tab next to the \code{Build} on the upper hand side of the screen.

# Initiate git
usethis::use_git()

Now check \code{Tools} menu, project options. In the Git/SVN, the version control should be set on Git.

Document your functions

Go inside your function and from the \code{Code} Menu, select "Intesert Roxygen Skeleton"

#' Title
#'
#' @return
#' @export
#'
#' @examples
hello <- function() {
  print("Hello, world!") 
}

By editing the header of your function, you can use \code{roxygen} to create the function document. Go to the \code{Tools} menu and project options. From \code{Build Tools} select "Generate document with roxygen and inside the Roxygen options, select "Install and restart". Now, each time we install the package, roxygen will create documentation for each function.



Javad-mun/rubin documentation built on June 5, 2019, 11:01 a.m.