Useful Rstudio shortcuts

replace Cmd (macOS) by Ctrl for PC

For projects

url <- "https://rworkshop.uni.lu/lectures/data/example.csv"
url_file <- here::here("data", basename(url))
url_file
## [1] "/builds/aurelien.ginolhac/rworkshop/data/example.csv"
# download if file is not present
if (!file.exists(url_file)) {
  message(paste("downloading", url, "to", url_file))
  download.file(url, url_file)
}
## downloading https://rworkshop.uni.lu/lectures/data/example.csv to /builds/aurelien.ginolhac/rworkshop/data/example.csv
## Warning in download.file(url, url_file): URL https://rworkshop.uni.lu/lectures/
## data/example.csv: cannot open destfile '/builds/aurelien.ginolhac/rworkshop/
## data/example.csv', reason 'No such file or directory'
## Warning in download.file(url, url_file): download had nonzero exit status
message("testing again, no download this time")
## testing again, no download this time
if (!file.exists(url_file)) {
  message(paste("downloading", url, "to", url_file))
  download.file(url, url_file)
}
## downloading https://rworkshop.uni.lu/lectures/data/example.csv to /builds/aurelien.ginolhac/rworkshop/data/example.csv
## Warning in download.file(url, url_file): URL https://rworkshop.uni.lu/lectures/
## data/example.csv: cannot open destfile '/builds/aurelien.ginolhac/rworkshop/
## data/example.csv', reason 'No such file or directory'

## Warning in download.file(url, url_file): download had nonzero exit status