Using RClimate To Retrieve Climate Series Data

January 23, 2011

(This article was first published on Climate Charts & Graphs I » RClimate Script, and kindly contributed to R-bloggers)

This post shows how to use RClimate.txt to retrieve a climate time series and write a csv file in 5 lines of R script.

One of my readers, Robert, wants to be able to download climate time series data and write it to a csv file.  The R script below shows how to  download the MEI data series and write a csv file.  For this example I will use the RClimate function (func_MEI) to retrieve the data. I then simply specify the path and file name link for the output file (note quotes around the output file name and then write  a csv file.

m <- func_MEI()
output_link <- "C://R_Home/mei.csv"
write.csv(m, output_link, quote=FALSE, row.names = F)

Let’s walk through the lines to see what is going on:


This line is telling R to read and have available the R script functions in the source file.

m <- func_MEI()
This line is telling R to assign the results of func_MEI() to the m data.frame. I have added 20 climate time series to RClimate similar to func_MEI.

This line displays the first 6 lines of the m data.frame so that we can be sure that func_MEI() returned some data.

output_link <- “C://R_Home/mei.csv”
This line assigns the target file path and name where I want the csv file saved.

write.csv(m, output_link, quote=FALSE, row.names = F)
This line writes the m data to a csv file located at the path and fie name specified in output_link.

If I want to see the func_MEI() R script, I just have to enter func_MEI in the R console  and R will display the func_MEI() script on the console.

Filed under: Citizen Climate Science, Do-it-yourself Climate Science, Global Warming, RClimate Script Tagged: Climate Trends, R scripts

To leave a comment for the author, please follow the link and comment on their blog: Climate Charts & Graphs I » RClimate Script. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, 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.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)