【问题标题】:Reading csv files and create paths读取 csv 文件并创建路径
【发布时间】:2017-04-13 06:24:07
【问题描述】:

我正在尝试复制以下代码来模拟一些图表,但在下载时出现错误(我猜)并读取 .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

【问题讨论】:

  • 请适当标记您的问题。看来您使用的是R,所以添加它。
  • @Ansjovis86 我的印象是OP没有在当前工作目录中创建input目录,这会阻止R创建csv文件。

标签: r csv


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2013-11-16
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 2013-03-02
    相关资源
    最近更新 更多