“sinkr” – a collection of functions featured on “me nugget”

September 2, 2014
By

(This article was first published on me nugget, and kindly contributed to R-bloggers)

The R package sinkr (version 1.0) has now been released:  https://github.com/menugget/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):

library(devtools)

install_github("sinkr", "menugget")

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 (used by eof)
  • dineof - Data Interpolating Empirical Orthogonal Functions
  • earthBear - Directional bearing between two geographic locations
  • earthDist - Earth distance between two geographic locations
  • eof - Empirical Orthogonal Functions analysis (specifically for gappy data)
  • eofRecon - EOF reconstruction
  • expmat - Exponentiation of a matrix
  • gmtColors - Generic Mapping Tools (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
  • 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 locations
  • plotStacked - Stacked plot
  • plotStream - Stream plot
  • round2reso - Round to defined resolution increment
  • spirographR - Make a sprirograph-like design
  • 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.

To leave a comment for the author, please follow the link and comment on his blog: me nugget.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.