Using RClimate To Retrieve Climate Series Data

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.

9 responses to “Using RClimate To Retrieve Climate Series Data

  1. Kelly,
    I used both methods, and both worked well.

    Thanks again for your site!

  2. Thanks Kelly. I used five of your functions to download the major temperature data sets. This was much easier and more accurate than my usual method of manually updating the data.


    • Stephen

      Thanks for the feedback. I’m glad to hear you are using some of my RClimate functions.

      Can you tell me how you use them, source(RClimate.txt) or did you copy/paste the functions to your computer?

  3. Hey Kelly,
    I’m having a look at them now. Did you ever end up doing the follow up post on regression analysis using least squares because you did one indicating the problems with the one used by excel.

    • Robert

      I have not written that post yet. Take a look at the John Fox article that I linked at the end of the post. R has a gls() package that avoids the ordinary least squares issues with time series.

    • Hey from what I can see you’re talking about the GLS package but I can’t seem to find it to download it. I’m reading through the Fox article now. Thanks.

    • Its the gls() function in the nlme package.

  4. Works like a dream. I’m glad you did this. Do you have any resources on Linear Regression and Multiple Regression analysis with R? Or is that covered in the Learn_R modules?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s