npm is the best package manager, so let's use it for R packages.
You'll need npm in order to install packages. npm comes with node, so just Install node.
You'll need nprm in order to create and load packages. Install nprm like you would any other R package.
library(devtools)
install_github('nprm', 'tlevine')
Here are three common things you might want to do.
source
but better).Let's define tau in one file.
# sub.r
library(nprm)
exports <- pi * 2
And then let's load it into another.
# super.r
library(nprm)
tau <- nprm.require('./sub.r')
print(tau)
Let's use treasury.io in our R script.
Install it from the shell.
npm install r-treasury.io
library(nprm)
treasury.io <- nprm.require('treasury.io')
treasury.io('SELECT * FROM t3c LIMIT 4')
To publish something to npm, you just need to do this.
package.json
file.npm publish
.Get a basic package.json
by running npm init
.
npm init
The main thing you'll need to add is the dependencies.
In the case of the previous script, your package.json
might look like this.
{
"name": "r-treasury.io",
"version": "0.0.2",
"description": "Submit a sql query to treasury.io and return a data.frame",
"main": "main.r",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/tlevine/r-treasury.io"
},
"keywords": [
"r", "nprm"
],
"author": {
"name": "Thomas Levine"
},
"license": "BSD-2-Clause",
"bugs": {
"url": "https://github.com/tlevine/r-treasury.io/issues"
},
}
(Prefix the package name with r-
so people don't think it's
a node package.)
Then make an account and run npm publish
.
npm publish
Since it's so easy to write packages, you can actually do this for pretty much anything that you write as long as it doesn't contain any secrets.
Now that you're using npm, there are a lot of way-cooler things that you can do, pretty much all from the npm command-line interface.
npm init
detects required packages. This doesn't.source
geom_taco
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.