timriffe / TR1

Read Human Mortality Database and Human Fertility Database Data from the Web
10 stars 4 forks source link

Fix problems reading from Human Fertility Database website #4

Closed jasonhilton closed 6 years ago

jasonhilton commented 6 years ago

The readHFDweb function and associated utility functions were no longer working because (I think) the HFD website moved from http to https. These problems are fixed by using the httr library instead of Rcurl. This also simplifies the authentication.

I did not make any changes to the way HMDHFDplus manages HFD credentials (in contrast to previous discussion), as I think it is probably easier to manage this inside a script after all.

A simple test

library(HMDHFDplus)

user <- Sys.getenv("HFD_user")
pass <- Sys.getenv("HFD_pass")
births <- readHFDweb("GBRTENW", item="birthsVV", 
                     user=user,password=pass)

expos <- readHFDweb("GBRTENW", item="exposRR", 
                     user=user,password=pass)

countries <- getHFDcountries()

country <- sample(countries,1)

# the itemavail function only works if logged in (e.g. after readHFDweb has been called once)
items <- getHFDitemavail(country) 
item <- sample(items,1)
df <- readHFDweb(country, item, user=user, password=pass)

print(country)
print(item)
class(df)
head(df)

# asks to choose an item when user-specified item doesn't exist.
df <- readHFDweb(country, "blibble", user=user, password=pass)
timriffe commented 6 years ago

much appreciated JH, will see about fixing readHMDweb now, hopefully the same httr stuff works there too