In this tutorial, we'll learn how a single line of R gets you access to all of the powerful utilities, algorithms, API calls, visualizations (and more) in the Blockspring community library.
First, install and load the devtools package. From within R, enter:
Next, install Blockspring. From within R, enter:
The Blockspring package is now installed! To load it into your R environment, simply enter:
Your first run: check the weather.
Let's check the weather in one line of R:
res <- blockspringRunParsed("weather-for-zip-code", list(zip_code = "94109"))
The weather in San Francisco doesn't change much, so you should probably see something like this:
print(res$params$weather)  "San Francisco, CA | 60.6° | Partly Cloudy"
You ran your first Blockspring function. Let's explain how that worked.
Blockspring functions in a nutshell
When you ran
blockspringRunParsed, here's what happened:
- Blockspring used your function name to find Get Weather for Zip Code, a simple weather scraper written in Python and submitted by user jtokoph.
- Get Weather for Zip Code quickly executed in the cloud, with your zip code passed through as an input argument.
- You received the results back in R and printed out the weather, found in
That instant replay should raise some questions. Let's answer them.
A quick Q+A
Where do I find more Blockspring functions?
Browse the community library to find utilities, algorithms, API calls, visualizations, and more. You're now a quick search away from programming just about anything.
Great, I found a function. How do I run it?
Click "Integrations" on the function's homepage, choose R, and copy and paste the given code snippet to wherever you need it. Try it yourself with Get Weather for Zip Code.
How do I know what inputs my function requires?
Again, click Get Weather for Zip Code, go to "Integrations", click R, and you'll see in the given code snippet the only input required is zip code. The snippets are helpful for finding a function's required input arguments.
How do I know where to find the function output?
The output is found in the result's
res$params. Explore that variable to find the output you're looking for. To learn more about the response, visit the api reference.
How do I create my own Blockspring function?
Visit the next R quickstart to learn how to add your own function to Blockspring.
Your second run: interactive google map
Let's create an interactive Google map in one line of R. You should try this in RStudio because we'll use
file.show to render the map right away.
res = blockspringRunParsed("interactive-google-map", list( locations = list( c("Latitude", "Longitude", "Tooltip"), c(37.4217542234, -122.100920271, "Somewhere"), c(41.895964876906, -87.632716978217, "Out"), c(28.58230778, 77.09399505, "There") ) ))
In RStudio open up your Google map and you should see the following:
Let's print out
res$params$map to take a look at how the function worked.
print(res$params$map)  "/var/folders/6w/920995kj30d_tn8skl8ml5wr0000gn/T//RtmpYMBrLW/165f6491e48ac-map.html"
This function saves the interactive Google map as an HTML file to a temporary directory on your machine, and sets that location to
res$params$map. That means you can open map as you would open any HTML file.
Your third run: summarize a URL
This time, let's summarize a URL in a line of R.
We'll also enable caching. If the summarization was done within the last 3,600 seconds, you'll receive it right away instead of needing to re-run the function.
res <- blockspringRunParsed("summarize-text", list( "url" = "http://www.usatoday.com/story/life/music/2015/04/18/rock-hall-of-fame-2015-induction-ceremony/25913423/", "sentences" = 1 ), list( "cache" = T, "expiry" = 3600 )) print(res$params$summary) # Such was the case Saturday night at the 30th annual gathering, which saw the inductions of Ringo Starr, Bill Withers, Joan Jett and the Blackhearts, Stevie Ray Vaughan & Double Trouble, the Paul Butterfield Blues Band, Green Day, Lou Reed and the "5'' Royales.
Become a Blockspring pro
Blockspring lets you program just about anything with a single line of Ruby and you're well on your way. You now know how to:
- Run Blockspring functions,
- Search for Blockspring functions, and
- A bit of background behind how Blockspring works.
You can also add your own public (or private) functions to Blockspring. Any function you add to Blockspring can be easily run across languages, chained, composed, cached, and shared with others, without any set up or maintenance. Check out the next quickstart tutorial to learn how to create your first Blockspring function.
Discover new functions Work at Blockspring