Tuesday, September 2, 2014

"sinkr" - a collection of functions featured on "me nugget"

The R package sinkr (version 1.0) has now been released:  https://github.com/marchtaylor/sinkr

I have finally gotten around to learning how to create an R package and decided to start by bundling functions that I have featured on the blog. Thanks to the R Studio team for making this so easy (in combination with the R packages roxygen2 and devtools). In addition to the great tips on the R Studio website,  I found the following Youtube videos helpful along the way:
Being new to the world of R packages (and due to the eclectic nature of the functions in sinkr), I'm not confident to upload this to CRAN. But, one can easily install the package using devtools and the following code (see https://github.com/hadley/devtools for OS-specific package updating tips):



For those using functions that were featured on this site in the past, the present versions may differ slightly, especially in the case of function names. For example, function names like plot.stacked were getting associated with the general plot function during the package build and thus "." characters have been removed from all function names (e.g. plotStacked).

sinkr functions include:

  • addAlpha                Add alpha channel (transparency) to colors
  • bioEnv                  Clarke and Ainsworth's BIO-ENV routine
  • bvStep                  Clarke and Ainsworth's BVSTEP routine
  • cov4gappy               Covariance matrix calculation for gappy data
  • dineof                  DINEOF (Data Interpolating Empirical Orthogonal
  • earthBear               Directional bearing between two geographic
  • earthDist               Earth distance between two geographic locations
  • eof                     EOF (Empirical Orthogonal Functions analysis)
  • eofBoot                 Calculate number of non-mixed EOFs (eof
  • eofNull                 Calculate significance of EOFs compared to a
                            null model (eof version)
  • eofRecon                EOF reconstruction (Empirical Orthogonal
                            Functions analysis)
  • expmat                  Exponentiation of a matrix
  • fieldAnomaly            Calculate the daily or monthly anomaly of a
  • getcolors               Select colors visually
  • gmtColors               GMT palette colors
  • imageScale              Make a color scale to accompany an image or
                            other plot
  • jetPal                  jet palette
  • lonLatFilter            Filter lon/lat positions that fall within
                            defined boundaries
  • lsos                    List top n objects by size
  • matrixPoly              Make polygons from a matrix
  • nearest                 Calculate the nearest element in a vector as
                            compared to a reference value
  • newLonLat               Directional bearing between two geographic
  • newRange                Define a new range for a numeric
  • northTest               North's Rule of Thumb for EOF significance
  • plotStacked             Stacked plot
  • plotStream              Stream plot
  • prcompBoot              Calculate number of non-mixed EOFs (prcomp
  • prcompNull              Calculate significance of EOFs compared to a
                            null model (prcomp version)
  • prcompRecon             prcomp object reconstruction
  • round2reso              Round to defined resolution increment
  • spirographR             Make a sprirograph-like design
  • unscale                 Unscale a matrix
  • val2col                 Convert values to color levels

    I can recommend package creation to anyone who wants greater control and clearer documentation of functions. I also used to do a lot of numbering of R scripts to keep track of versions (e.g. "plotstacked.03.R"). R studio combined with GitHub has been a real revelation to me in this regard (thanks to Tal Galili for the final nudge!: http://datascience.la/a-conversation-with-tal-galili-at-user-2014/).

    I hope that future function examples will be easier to reproduce through simple loading of the sinkr package.

    No comments:

    Post a Comment