0

I am trying to replicate the following code to simulate some charts and I got error at the time of download (I guess) and read the .csv file. The problem is that I do not know how or where to create the "input" directory, how to put the path in the command line and if the data would be downloaded. Anybody could help? Thanks for your time!

library(idbr)
library(countrycode)
library(ggplot2)
library(animation)
library(dplyr)


countries <- c("France", "Switzerland", "Japan", "China", "United States", "Brazil", "Russia", "Morocco")
country.iso2 <- countrycode(countries, "country.name", "fips104")

translation.file <- "input/Population structures past and forecast - Sheet1.csv"

downloadData <- F

years <- 1990:2050
apikey <- "901083ee90dbd111d13f5e270ca00b4abf654be6"
data.file <- paste0("input/", paste(range(years), collapse = "_"), "_", 
paste(country.iso2, collapse = "_"), ".csv")

### load translations
txt <- read.csv(translation.file, row.names = 1, stringsAsFactors = F)

Error in file(file, "rt") : no se puede abrir la conexión
Además: Warning message:
In file(file, "rt") :
no fue posible abrir el archivo 'input/Population structures past and forecast - Sheet1.csv': No such file or directory
Julien Marrec
  • 11,605
  • 4
  • 46
  • 63
José
  • 189
  • 7

1 Answers1

0

Googling for r create dir led me to this SO question which shows that you can use dir.create to create directories. Note that you need to have write privileges at the location you create the directory, for example your home drive. You can use tempdir() to get a temporary directory where you can store stuff, this works portably for Linux, Windows and Mac.

Community
  • 1
  • 1
Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149