1 Setting up

The HIEv R package is not available on CRAN, and must be installed with the devtools package as follows. Windows users must have Rtools installed.

library(devtools)
install_bitbucket("remkoduursma/HIEv")

Also use this command to update the HIEv R package, which I recommend you do every so often.

Then load the package as usual,

library(HIEv)

To be able to communicate with the HIEv, you have to set the API token. This token can be found by logging into the HIEv, click on your email address in the top-right, then ‘Settings’, and the API token will be shown. You can set this token in a few different ways, but I strongly recommend you store it in a separate text file, not include it in your scripts. You must take care to not share the token publicly.

Paste the token in a text file, and set the token every time you use the HIEv R package, like so:

# If the token is stored in a text file in the current working directory
setToken(tokenfile="mytokenfile.txt")

# On Windows, if you store your token in 'c:/hiev/token.txt', you can just do:
setToken()

3 Downloading files

To download files from the HIEv, it is necessary to first perform the search. It is also important to set the path to which files are to be downloaded. If you do nothing, it will be the current working directory, which is probably not a good idea if you want to keep your files organized.

# Set download path for the current session
setToPath("c:/temp")

# I prefer to keep files in a subdirectory of the current working directory,
setToPath("cache")

Note that the directory has to exist, it will not be created for you.

To download a single file, we first do a search and store it in an object,

s <- searchHIEv("WTC_TEMP_CM_LEAFCARB_20130515-20140402_L2.csv")
## Your search returned 1 records.
## 
## Filenames (max.10):                      Permission:
##   1 WTC_TEMP_CM_LEAFCARB_20130515-20140402_L2.csv       Yes

and then download the files returned by the search,

downloadHIEv(s)
## Downloading 0 Kb.
## 
## Skipping WTC_TEMP_CM_LEAFCARB_20130515-20140402_L2.csv - file exists.
## Done.
## Files were downloaded into : C:/repos/hiev/vignettes
## Some files were skipped. To redownload these files, delete the local copy.

If multiple files are found by the search, all will be downloaded. Alternatively, set the which argument to specify which files of the search to download.

Note : the downloadHIEv function does not download more than 50 files unless the user requests this. This is to avoid accidental very large downloads. To override, use the command downloadHIEv(mysearch, maxnfiles = 1000).

3.1 Searching, downloading and reading CSV and TOA5 files

For CSV (comma-separated values) and TOA5 (automated logger output) files, the HIEv R package has two convenience functions that search, download and read the files from HIEv. For example,

leafcarb <- downloadCSV("WTC_TEMP_CM_LEAFCARB_20130515-20140402_L2.csv")  # CSV
## Your search returned 1 records.
## 
## Filenames (max.10):                      Permission:
##   1 WTC_TEMP_CM_LEAFCARB_20130515-20140402_L2.csv       Yes
## 
## 
## Downloading 0 Kb.
## 
## Skipping WTC_TEMP_CM_LEAFCARB_20130515-20140402_L2.csv - file exists.
## Done.
## Files were downloaded into : C:/repos/hiev/vignettes
## Some files were skipped. To redownload these files, delete the local copy.
## Reading files...done.
faceair <- downloadTOA5("FACE_R1_B1_AirVars_20160131.dat") # TOA5
## Your search returned 1 records.
## 
## Filenames (max.10):                      Permission:
##   1 FACE_R1_B1_AirVars_20160131.dat                     Yes
## 
## 
## Downloading 2.04 MB.
## 
## ---=== Downloading file 1 of 1 (2.04 MB) -- FACE_R1_B1_AirVars_20160131.dat
## Done.
## Files were downloaded into : C:/repos/hiev/vignettes
## 
## Reading files...done.
## Combining dataframes...done.

When multiple files match the search string, both functions attempt to row-bind the results into one dataframe. This is most useful for timeseries data from automated loggers. For example,

airvar <- downloadTOA5("FACE_R1_B1_AirVars", startDate="2015-10-1", endDate="2016-1-15")
## Your search returned 4 records.
## 
## Filenames (max.10):                      Permission:
##   1 FACE_R1_B1_AirVars_20160131.dat                     Yes
##   2 FACE_R1_B1_AirVars_20151031.dat                     Yes
##   3 FACE_R1_B1_AirVars_20151130.dat                     Yes
##   4 FACE_R1_B1_AirVars_20151231.dat                     Yes
## 
## 
## Downloading 8.93 MB.
## 
## Skipping FACE_R1_B1_AirVars_20160131.dat - file exists.
## ---=== Downloading file 2 of 4 (3 MB) -- FACE_R1_B1_AirVars_20151031.dat
## ---=== Downloading file 3 of 4 (2.91 MB) -- FACE_R1_B1_AirVars_20151130.dat
## ---=== Downloading file 4 of 4 (3.01 MB) -- FACE_R1_B1_AirVars_20151231.dat
## Done.
## Files were downloaded into : C:/repos/hiev/vignettes
## Some files were skipped. To redownload these files, delete the local copy.
## 
## Reading files...done.
## Combining dataframes...done.

Both functions will look for a DateTime variable, which will be converted to a POSIXct class with standard methods (or see datetimevar and posixctFormat arguments). This makes life easy,

# Plot not shown
with(airvar, plot(DateTime, PAR_Den_2_Avg, type='l'))