Skip to content
/ sealR Public

R package for common R code from Spatial Ecosystem Analytics Lab at NCSU

Notifications You must be signed in to change notification settings

ncsuSEAL/sealR

Repository files navigation

sealR

R package for common R code from SEAL lab at NCSU

Installation

Please install using devtools.

devtools::install_github("ncsuSEAL/sealR")
library(sealR)

Adding functions to this package

This how-to comes from https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/. Also see this site for more in-depth information.

Example

Let's say you love dogs so much, you don't want just one picture of a dog at a time to cheer you up. You want 10 of them (or 100. or 1000). This is a real-world example.

  • to see what this looks like when completed, use the website above or run the code below to follow along:
devtools::install_github("ncsuSEAL/sealR")
library(sealR)
?doggo

First, it's helpful to be using the sealR.Rproj. Otherwise, you need to setwd("./sealR").

Create a new .R file containing only the function and save in the "R" folder of this repo.

doggo <- function(num){
    if(!require(pupR)){devtools::install_github("melissanjohnson/pupR"); library(pupR)}
    
    replicate(num, pupR())
}

Then add the documentation lines like this. You don't need to save.

#' A Dog Function
#'
#' This function allows you to express your love of dogs.
#' @param num Do you love dogs? The number corresponds to how many dog pictures you would like to see to cheer you up.
#' @keywords dogs
#' @export
#' @examples
#' doggo()
 
doggo <- function(num){
    library(pupR)
    
    replicate(num, pupR())
}

Now in the console, run the following. This will automatically save and add the documentation to the package.

library(dev_tools)
library(roxygen2)
document()

That's it! To install the new version of the package, use install_github("mcgregorian1/sealR").

Notes for updating packages

I've noticed a situation where even when you update the documentation for a package and re-download the package using devtools, the help file is not updated. If you run across this, then do the following steps to force the .rd file to change (this is generated by the roxygen package as the Help file that R uses).

  • Clone the sealR repository to your computer.
  • In R, run roxygen2::roxygenise("/Volumes/GoogleDrive/My Drive/github/sealR").
  • Then load the version of the package that's now updated, using devtools::load_all("/path/to/package/folder")
  • Check the help file and make sure it looks good. ?sealR::packageName.
  • Once you're glad with it, push to GitHub. Now when you download the package again using devtools, it will be fully fixed.

I'm not sure why this is happening - normally the updating of the .rd file should automatically occur via roxygen when you compile and download the package to R, but oh well.

About

R package for common R code from Spatial Ecosystem Analytics Lab at NCSU

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages