knitr::opts_chunk$set(echo = TRUE)
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.
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.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.