R/utils.R

Defines functions valid_year get_if_not_exists nla_path

nla_path <- function(){
  res <- file.path(rappdirs::user_data_dir(), "nlaR")
  dir.create(res, showWarnings = FALSE)
  res
}

get_if_not_exists <- function(url, destfile){
  if(!file.exists(destfile)){
    download.file(url, destfile)
  }else{
    message(paste0("A local copy of ", url, " already exists on disk"))
  }
}

valid_year <- function(year){
  if(!(year %in% c(2007, 2012))){
    stop("nlaR only serves the 2007 and 2012 data")
  }
}
jsta/nlaR documentation built on March 23, 2023, 11:53 p.m.