读取csv文件并创建路径

时间:2016-11-29 09:57:30

标签: r csv

我正在尝试复制以下代码来模拟一些图表,我在下载时遇到错误(我猜)并阅读.csv文件。问题是我不知道如何或在何处创建“输入”目录,如何将路径放在命令行中以及是否将下载数据。有人可以帮忙吗?谢谢你的时间!

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

1 个答案:

答案 0 :(得分:0)

Google r create dir的Google搜索引导我this SO question,这表明您可以使用dir.create创建目录。请注意,您需要在创建目录的位置具有写权限,例如您的主驱动器。您可以使用tempdir()来获取可以存储内容的临时目录,这适用于Linux,Windows和Mac。

相关问题