【问题标题】:Escape readLines() function in RStudio在 RStudio 中转义 readLines() 函数
【发布时间】:2019-05-13 15:17:27
【问题描述】:

由于我使用 R 做的工作,我需要使用readline() 函数来输入文本。有时会出现问题,而不是写readline() 我意外地运行readLines()(由于自动完成或任何原因)。

一旦我运行了readLines(),我就无法逃避这个函数。我可以继续写,但无法在控制台中恢复提示(无法运行任何代码),因为我不知道如何关闭 readLines() 函数调用。有什么线索吗?

请注意,此问题仅发生在 RStudio 中(并且根据 cmets 中的 Matt 所说,Visual Studio)。

【问题讨论】:

  • @Matt 我以前试过这些,现在有用!不知道怎么回事
  • 如果您使用的是普通终端(不是 RStudio),则可以使用 ctrl + c 来中断任何进程。 RStudio 控制台有时更令人沮丧。 esc 应该停止大多数进程,但它并不总是有效。有时按esc 多次会有所帮助,有时则无济于事。在这种情况下,我通常只需使用 cmd + shift + F10 重新启动 R(Mac,不确定 PC 是否相同)。
  • @gersht 这就是我目前所做的(我使用 RStudio),但我很惊讶没有命令存在 readLines() 提示符。
  • @BenBolker 不管怎样,这个问题在 MS Visual Studio 中也发生在我身上。

标签: r console rstudio


【解决方案1】:

不是一个完美的修复,但您可以使用debug()。任何时候你不小心最终调用了readLines(),你可以通过输入Q退出browse[2]

debug(readLines)
readline()
asdf

[1] "asdf"

readLines()
debugging in: readLines()
debug: {
    if (is.character(con)) {
        con <- file(con, "r")
        on.exit(close(con))
    }
    .Internal(readLines(con, n, ok, warn, encoding, skipNul))
}

Browse[2]&gt; Q

readline()
asdf

[1] "asdf"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    相关资源
    最近更新 更多