readHFCweb: readHFCweb get HFC data straight from the web into R!

View source: R/readHFD.R

readHFCwebR Documentation

readHFCweb get HFC data straight from the web into R!


This concatenates the necessary url and calls read.csv() with all the necessary defaults to avoid annoying surprises. Age is given as an integer, along with an AgeInterval. The default behavior is to change the AgeInterval column to character and produce a logical indicator column, OpenInterval. Year is also given as the starting year of a YearInterval, rather than the original Year1 and Year2 columns. The column Country is renamed CNTRY. All other original columns are maintained. Output is invisibly returned, so you must assign it to take a look.


readHFCweb(CNTRY, item, fixup = TRUE, ...)



character string of the HCD short code. Only one! Run getHFCcountries(FALSE) to see what the options are.


character string of the data product code, which is the base file name, but excluding the country code and file extension .txt. For instance, "ASFRstand_TOT", "ASFRstand_BO", "TFRMAB_TOT", "TFRMAB_BO". Only one item!


logical. Default TRUE. Should column classes be coerced to those more similar to HFD, HMD?


optional arguments passed to read.csv(). Not required.


## Not run: 
DF <- readHFCweb("CZE","TFRMAB_TOT")
DF <- readHFCweb("CZE","ASFRstand_BO")

# get ASFRstand_BO for all countries where available:
Countries <- getHFCcountries()
# takes a minute to run

urls <- paste0("", 
               Countries,"/", Countries, "_",  "ASFRstand_BO", ".txt")

HaveBO <- RCurl::url.exists(urls)
 # we grab data for these countries:
 (Countries <- Countries[HaveBO])

# Also takes 1-15 min depending on internet connection and machine
# read in one at a time and stick together into long data.frame
allBO <-,
        # this is the iteration of reading in
        lapply(Countries, function(CNTRY){
            readHFCweb(CNTRY, item = "ASFRstand_BO")
             })) # closes off the meta-rbind thingy
dim(allBO) # [1] 133237     31

## End(Not run)

HMDHFDplus documentation built on Feb. 16, 2023, 8:34 p.m.