R/hello.R

library(devtools)
library(roxygen2)
library(readr)

getwd()

dir()

pckname<-"LiXinfengTools"

devtools::create(pckname)
dir(pckname)

loc<-paste(getwd(),pckname,sep="/")
descLoc<-paste(loc,"DESCRIPTION",sep="/")
readLines(descLoc)

desc<-readLines(descLoc)
desc[grep("Title",desc)]<-"Title: LiXinfengTools"
desc[grep("Version:",desc)]<-"Version: 0.0.1"
desc[grep("Authors",desc)]<-"Authors@R: person(\"Xinfeng\", \"Li\", email = \"li000027@umn.edu\", role = c(\"aut\", \"cre\"))"
desc[grep("Description",desc)]<-"Description: Tools for Quiz3."
desc[grep("License",desc)]<-"License: MIT + file LICENSE"
writeLines(desc,con=descLoc)

write_file(x="
           YEAR: 2018
           COPYRIGHT HOLDER: Xinfeng Li
           ", path=paste(loc,"LICENSE",sep="/"))

file.copy(paste(getwd(),"RFunctionsForPackage.R",sep="/"), paste(loc,"R",sep="/"))
file.rename(paste(loc,"R","RFunctionsForPackage.R",sep="/"),paste(loc,"R",paste(pckname,"Rfunctions.R",sep=""),sep="/"))



devtools::document(loc)


d <- read.table(url("http://www.stat.umn.edu/geyer/3701/data/q1p4.txt"),header = TRUE)
devtools::use_data(d,pkg=loc)


write_file(x=
             "
           #' Example data from HW 3
           #'
           #' @author Charlie Geyer \\email{geyer@umn.edu}
           #' @references \\url{http://www.stat.umn.edu/geyer/3701/data/q1p4.txt}
           \"d\" ",path=paste(loc,"R","data.R",sep="/"))


devtools::document(loc)

d2 <-read.csv("http://users.stat.umn.edu/~almquist/3811_examples/gapminder2007ex.csv")
devtools::use_data(d2, pkg=loc)

write_file(x=
             "
           #' second dataset for HW 3
           #'
           #' @author Zack W. Almquist \\email{almquist@umn.edu}
           #' @references \\url{http://users.stat.umn.edu/~almquist/3811_examples/gapminder2007ex.csv}
           \"d2\" ",path=paste(loc,"R","data2.R",sep="/"))


devtools::document(loc)

d3 <- read.csv("http://www.stat.umn.edu/geyer/3701/data/q1p1.txt")
devtools::use_data(d3,pkg=loc)

write_file(x=
             "
           #' Third dataset for HW 3
           #'
           #' @author Charlie Geyer \\email{geyer@umn.edu}
           #' @references \\url{http://www.stat.umn.edu/geyer/3701/data/q1p1.txt}
           \"d3\" ",path=paste(loc,"R","data3.R",sep="/"))

# Build comments for the data
devtools::document(loc)


# Build Test Framework (for unit tests of functions)
use_testthat(loc)

# copy R functions to file in package
file.copy(paste(getwd(),"UnitTestForRfunctions.R",sep="/"), paste(loc,"tests","testthat",sep="/"))
file.rename(paste(loc,"tests","testthat","UnitTestForRfunctions.R",sep="/"),paste(loc,"tests","testthat",paste(pckname,"func1_func2.R",sep=""),sep="/"))


# At this point let's do an R Check
# And an R build
devtools::check(loc)
devtools::build(loc)

# Add function that requires ggplot2

# copy R functions to file in package
file.copy(paste(getwd(),"RFunctionsWdependencies.R",sep="/"), paste(loc,"R",sep="/"))
file.rename(paste(loc,"R","RFunctionsWdependencies.R",sep="/"),paste(loc,"R",paste(pckname,"myplot.R",sep=""),sep="/"))

## Add dependancies to R package
# Dependancies
use_package("ggplot2",pkg=loc)
use_package("magrittr", pkg=loc)
use_package("tidyverse", pkg =loc)
use_package("dplyr", pkg=loc)

# Add Manuals
devtools::document(loc)


# At this point let's do an R Check, again
# And an R build
devtools::check(loc)
devtools::build(loc)



# Let's now document the whole package
use_package_doc(loc)

# Add Manuals
devtools::document(loc)

## Let's build a vignette
devtools::use_vignette("introduction",pkg=loc)

# At this point let's do an R Check, again
# And an R build
devtools::check(loc)
devtools::build(loc)


# Last let's install it on our machine
devtools::install()
XINFENG66/XINFENGLI documentation built on May 25, 2019, 2:23 p.m.