【问题标题】:R Read table, keep quotes in stringR读取表格,将引号保留在字符串中
【发布时间】:2014-04-22 15:15:42
【问题描述】:

例如,我有一个文件,内容如下:

x=setwd('./blabla/bla'); system('python ........');
b=1,2,3
...

这是我需要保留和稍后处理的问题的列表。

我需要使用读取表,但我遇到的问题是字符串丢失了引号并变成:

setwd(./blabla/bla);

如何通过 read.table 阅读来保留引号?如果我使用quote="",它会给我一个错误:

扫描错误(文件、内容、nmax、sep、dec、引用、跳过、nlines、na.strings、:
第 1 行没有 4 个元素

【问题讨论】:

  • 不清楚x= 发生了什么。如果您在控制台中快速执行?read.table,您将看到quote: the set of quoting characters. To disable quoting altogether, use quote = "". See scan for the behaviour on quotes embedded in quotes. Quoting is only considered for columns read as character, which is all of them unless colClasses is specified,因此在调用中使用quote="" 应该可以工作。
  • 您确定要使用read.table 而不是source?我无法重现此内容,但您可以尝试read.table(..., quote = "")
  • 这看起来更像是source 的工作。导入后你想对文件内容做什么?
  • @hrbrmstr 我使用了 quote="" 参数,但我想我遇到的问题是每行有多个带引号的指令。我将在导入后评估内容。

标签: r


【解决方案1】:

我找到了解决方案,我需要按以下方式存储指令:

x="setwd('./blabla/bla'); system('python ........');"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 2013-12-13
    • 2010-09-09
    • 2023-01-13
    相关资源
    最近更新 更多