R/getData.R

Defines functions getData

Documented in getData

#' Example data-getting function
#'
#' @param url URL from which to get data
#' @param fname Filename to write
#' @param key A key passed to openssl::md5 to create new identifiers
#'
#' @return NULL
#' @export
#' @importFrom openssl md5
#'
#' @examples
#' getData(url = "https://www.dropbox.com/s/pq1oxe0zyedfzcq/testdata.csv",
#'   file = "testfile.csv",
#'   key = "demokeyvalue")
getData <- function(url, file, key=""){
  ifelse(Sys.info()['sysname']== "Windows",
         download.file(url, destfile="origfile", method = "wget", extra = "--no-check-certificate"),
         download.file(url, destfile="origfile", method = "wget"))
  #download.file(url, destfile="origfile", method = "wget")
  dataset <- read.csv("origfile", row.names = NULL)
  unlink("origfile")
  dataset <- mutate(dataset, newcodes = md5(as.character(originalID), key = key)) %>%
    select(-originalID)
  write.csv(dataset, file = gsub(":", "-", file))
  return(dataset)
}
waldronlab/chasingcovid documentation built on April 16, 2021, 6:23 p.m.