r - Why do I need to use mode = wb with download.file() for this .rds file? -
i getting hung on shiny apps tutorial lesson 5 because unable open counties.rds file. readrds() threw: error reading connection.
i figured out open .rds fine if downloaded download.file(url, dest, mode = "wb") or used browser download file local directory.
outstanding question: why counties.rds file not open if use download.file() without setting mode = "wb"? expect answer obvious like: "duh, counties.rds binary file." however, before try answer own question, i'd confirmation more experience.
repro steps:
download.file("http://shiny.rstudio.com/tutorial/lesson5/census-app/data/counties.rds", "counties.rds") counties <- readrds("counties.rds") error in readrds("counties.rds") : error reading connection resolution: download via browser or use binary mode (wb).
download.file("http://shiny.rstudio.com/tutorial/lesson5/census-app/data/counties.rds", "counties.rds", mode = "wb") counties <- readrds("counties.rds") # success!
my suggestion specify 'mode' regardless , pretty safe use mode="wb". argue latter should default , automatic recognition file extension faulty , should not relied upon, cf. https://stat.ethz.ch/pipermail/r-devel/2012-august/064739.html