I am trying to create a package to download, import and clean data from the Dominican Republic Central Bank web page. I have done all the coding in Rstudio.cloud and everything works just fine, but when I try the functions in my local machine they do not work.
After digging a bit on each function, I realized that the problem was the downloaded file, it is corrupt.
I am including the first steps of a function just to illustrate my issue.
I don't know if this is the best way to handle this multi-OS situation but I use a very similar approach, I use this function to get the OS and perform some tasks accordingly, obviously, this is not a general solution since it only works for the operating systems that I use, but it can give you an idea.
get_os <- function(){
sysinf <- Sys.info()
os <- sysinf['sysname']
if (os == 'Darwin'){
os <- "osx"
} else {
os <- .Platform$OS.type
if (grepl("^darwin", R.version$os))
os <- "osx"
if (grepl("linux-gnu", R.version$os))
os <- "linux"
if (grepl("linux-gnueabihf", R.version$os))
os <- "raspbian"
}
tolower(os)
}
This is supposed to be Windows-only but I have tested it on Ubuntu and it works normally so I would say, give it a try.
When I was facing your situation (lots of foul language was involved) I ended up sidestepping the issue and downloading via curl::curl_download().
It has other benefits in addition to being platform neutral, and it is imported by httr which in turn is used by just about everyone, so I did not feel so bad about creating a package dependency.