installing this package

as a user

This is the way to go if you want to reproduce the work.

If you do not have a ".tar.gz" file

Or if you don't know what this is. 1. Download the whole folder from github. - If you use git within RStudio : Download from within RStudio: Select (at the top right corner) new project > Version control > Git and in the field "Repository URL" give the link https://github.com/allanecology/BetaDivMultifun . chose a location where to store it. - If you don't use git : manually download and place in a folder of your choice. 2. From within R, set the R working directory to the parent folder of the downloaded package. (e.g. Downloads if you stored the package folder in Downloads.)

  1. Run the code below
# install.packages("devtools")
setwd("<parent-directory-of-the-package>")
devtools::install("BetaDivMultifun")

Note for above code section: - The devtools::install function also installs packages on which BetaDivMultifun depends on. - Update all packages when you are asked for by R (type 1 to the console)

TODO Noelle write about package error in windows.

Set wd back to the package

setwd("/home/noelleschenk/Desktop/BetaDivMultifun/")

If you do not with to further develop the package, but e.g. just reproduce the analysis, you are done now.

If you do have a ".tar.gz" file

If you have a ".tar.gz" file with the BetaDivMultifun package on it, you can install directly from that file. The ".tar.gz" file is called a "source"-type file.

install.packages("/home/noelleschenk/Desktop/BetaDivMultifun_0.1.tar.gz", type = "source", repos = NULL)

If you do not with to further develop the package, but e.g. just reproduce the analysis, you are done now.

install the package as a developer

This is the way to go if you want to further develop this analysis.

Literature

To create the package, I used the blogposts of: Hilary Parker, the book "R packages" and the idea of using R packages for an analysis is coming from Robert M. Flight's blogposts, where he explains why and how to use R package for an analysis.

Setup

Only if you like to work on the package (change it). I worked with following packages and RStudio, which is extremely well suited for package development.

If you are linux user, install the following packages with sudo apt-get install <packagename> - libssl-dev - libxml2 libxml2-dev - libcurl4-gnutls-dev (previously libcurl)

If you are not using Linux and there was any requirement, R will tell you in its error message as soon as you try to install the below mentioned packages.

# running these lines will take some time ...
install.packages("devtools")
library(devtools)
#devtools::install_github("klutometis/roxygen")
# the roxygen2 source possibly changed now
devtools::install_github("r-lib/roxygen2")
library(roxygen2)

Maintaining the package

changing code

After you generated/changed code of the package, the newly generated code needs to be loaded. (E.g. if you add a function and later want to use it.) Therefore, the function code as well as the functions documentation needs to be loaded as described below.

devtools::document()

check code

RStudio : Build > Check --> note : don't confuse with "test", this is something else.

test code

develop your own tests to prevent introducing bugs.

knit to html

By hand

rmarkdown::render('<pathtothisdocument>/1read_raw_dataset.Rmd')
rmarkdown::render('vignettes/function_imputation.Rmd', output_format = "html_document")

Note : knit will produce a .html file in a temporal directory (e.g. tmp/) to not clutter the "vignettes" folder with html files. To get a html file output, use the code above.

Update datasets

Updating the included datasets

Example : change dataset "model_names" :

# data("model_names") # loads the dataset

# IF change is done by hand
fwrite(model_names, "deleteme.csv") # write dataset to .csv in order to change by hand
model_names <- fread("deleteme.csv")

# IF change is done by hand
# just change the variable model_names

# overwrite dataset in /data folder with new version
save(model_names, "data/model_names.rda")
usethis::use_data(model_names, overwrite = T)
# document changes in the file R/data.R
# create new documentation
devtools::document()

# clean up
# in case you wrote to a .csv file, clean this up.


allanecology/multiFunBetadivLuiGDM documentation built on Nov. 12, 2023, 6:16 a.m.