README.md

R-ToolBox

Prologue

Any csv file, script (of any kind), or R function and pdf on GitHub, including those in this toolbox can be individually downloaded using the function gitAFile() found in this toolbox. (Which could initially be copied from the 'R' directory here and pasted into R.)

For example use:

gitAFile('John-R-Wallace-NOAA/JRWToolBox/master/R/lib.R') 
# lib() is saved to .GlobalEnv and also scrolled on the screen since show = TRUE (the default)
# Use the Raw view URL as a guide to the correct path, but note that in the URL a space ' ' codes as '%20' 
# In a file name '%20's can be left as spaces (they will be changed for you).

to view and download lib() into R. (The lib() function will install and update both GitHub and CRAN packages only if needed and regardless will load the package into the R session, if require = TRUE (the default).)

Note that the FUNCTION DOWNLOADED WILL HAVE ALL THE COMMENTS AND LINE SPACING INTACT, unlike functions within packages downloaded via the 'devtools' package (which, FYI, now calls the 'remotes' package).

See additional arguments of gitAFile() with str(gitAFile).

Customized wrappers for gitAFile can be made for often used packages, e.g.:

   S <- function (File, ...) {
        if (!(is.character(substitute(File)))) 
            File <- deparse(substitute(File))
        gitAFile(paste0("John-R-Wallace-NOAA/JRWToolBox/master/R/", File, ".R"), ...)
   }

so that only:

  S(gitAFile)

is needed to download and view gitAFile().

An example to directly display the pdf fully in a viewer and not on the GitHub web site:

gitAFile("https://github.com/James-Thorson/VAST/blob/master/manual/VAST_model_structure.pdf", "pdf")

To save a script (not an R function) as a file in the current working directory do, e.g.:

 gitAFile("John-R-Wallace-NOAA/Length_Restricted_Catch_with_VAST/master/Run_Data_and_VAST_by_Species.R", 'script', File = 'Run_Data_and_VAST_by_Species.R')

To download and put a function directly into an editor, copy and edit gitEdit()'s paths to a particular package and your favorite editor, e.g.:

  gitEdit(Table)

downloads JRWToolBox::Table() and puts it into notepad++ for editing (if one of the two paths to notepad++ in gitEdit is correct).

========================================================================================

Install or upgrade this package with:

# Get devtools if you don't already have it.
if (!any(installed.packages()[, 1] %in% "devtools"))  install.packages('devtools')

oldOpts <- options(download.file.method = "auto")  # Sometimes remotes::install_github() throws an error without this
remotes::install_github("John-R-Wallace-NOAA/JRWToolBox", force = TRUE)
options(oldOpts)

If you then want to load the package into R use:

library(JRWToolBox)

============================

Highlights and Comments

Code to put on the top of a function to start using lib() and other functions in JRWToolBox would look like:

if (!any(installed.packages()[, 1] %in% "devtools"))  
    install.packages('devtools')

if (!any(installed.packages()[, 1] %in% "JRWToolBox")) 
    devtools::install_github("John-R-Wallace/JRWToolBox")
require(JRWToolBox)

lib("John-R-Wallace/JRWToolBox")  # For keeping the toolbox updated

# Install other packages as needed from either GitHub or CRAN
lib("John-R-Wallace/Imap") # GitHub
lib(plyr) # CRAN

============================ All functions were written by me except for (this list is under construction):



John-R-Wallace-NOAA/JRWToolBox documentation built on Feb. 21, 2020, 2:37 p.m.