Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Last active December 16, 2015 15:49
Show Gist options
  • Save benmarwick/5458479 to your computer and use it in GitHub Desktop.
Save benmarwick/5458479 to your computer and use it in GitHub Desktop.
Basics package creation steps in RStudio and Github
# helpful information: http://robjhyndman.com/hyndsight/building-r-packages-for-windows/
#########
# Sketch of proecess
# start with
library(devtools)
library(roxygen2)
create("mypackage")
# edit the DESCRIPTION right away
# write functions and put documentation above the script
# don't forget to document the data also: http://adv-r.had.co.nz/Documenting-functions.html
# put raw data in the /vignettes directory - it wont work anywhere else
# put rmarkdown vignette in /vignettes and ensure DESCRIPTION is updated
# run these three frequently as functions are added and the vignette is worked on:
roxygenise("mypackage")
check("mypackage")
build("mypackage")
# share the tar.gz file that results from the build as the canonical version
#########
See below basic idea of:
DESCRIPTION # specify to make vignette from Rmd
my_function.r # example function for package
my_vignette.r # example vignette
# to make the PDF of the help
# windows cmd, then to Packaged folder, then R CMD Rd2pdf mypackage
# this will make the PDF
# getting it onto github: http://stackoverflow.com/a/17526158/1036500
Create empty repository on github (I will use name rpackage in this example)
Create package locally using devtools, create("rpackage") (this will create rpackage folder)
Create new project in RStudio (Create project from: Existing directory) and choose rpackage directory
In RStudio go to Git/More/Shell and type git init
Reopen the project (this will refresh the Git tab)
Start Git/More/Shell and type
git add *
git commit -m "first commit"
git remote add origin [email protected]:[username]/rpackage.git
git push -u origin master
Then you can refresh repository on github. Now you can close (or even delete) your local project and next time you can start a new project Project/New project/Version Control/Git
Package: mypackage
Title: What the package does (short line)
Version: 0.1
Authors@R: "First Last <[email protected]> [aut, cre]"
Description: What the package does (paragraph)
Depends:
R (>= 3.1.1)
License: MIT
LazyData: true
VignetteBuilder: knitr
Suggests:
knitr
#' my function
#' An example function
#' @export
#'
my_func <- function() Sys.time()
1 2 3
11 12 13
22 23 23
<!--
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Supplementary material for}
-->
```{r setup, message=FALSE, echo=FALSE}
library(knitr)
# This is necessary to direct knitr to find the
# 'data', and other directories that contain
# files needed to execute this document
# thanks to http://stackoverflow.com/a/24585750/1036500
opts_knit$set(root.dir=normalizePath('../'))
```
```{r}
library(mypackage)
myfunc()
```
```{r}
plot(rnorm(100))
mydata <- read.csv("data/mycsv.csv", header = FALSE)
mydata
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment