【问题标题】:VSC R debug console not reacting to input from userVSC R 调试控制台对用户的输入没有反应
【发布时间】:2021-12-28 00:15:14
【问题描述】:

我正在 VSC 中调试 R 脚本。此脚本记录到 Google API,因此它会提示用户从菜单中选择预授权帐户:

1: email1@email1.com
2: email2@email2.com

问题是在输入菜单选项(在我的情况下为1)并在DEBUG CONSOLE 中输入Enter 后,即使输入被接受并显示在控制台中,脚本也不会继续。

您可以在此处查看 DEBUG CONSOLE 的图像:

如您所见,进入菜单选项后没有任何反应(当我在 PyCharm 中调试此代码时,脚本在输入 1 后确实会继续)

【问题讨论】:

  • 我的意思是问你使用的是哪个调试器?本机调试器还是 Vsc 的扩展?我的建议是安装marketplace.visualstudio.com/… 看看是否能解决您的问题。
  • @Technophobe01 该扩展已安装,但问题仍然存在

标签: r debugging visual-studio-code vscode-debugger


【解决方案1】:

VSCode-R-Debugger 通过向 child 的标准输入发送输入来启动和控制 R 程序过程。要在调试模式下获取输入,您必须在调试控制台中输入数据并在其前面加上 ###stdin。该功能通过以下Github 请求进行描述并标记为已解决。我能够使用以下示例代码来确认解决方案是最新的并且按描述工作:

#!/usr/bin/env Rscript

typeline <- function(msg = "Enter text: ") {
  if (interactive()) {
    txt <- readline(msg)
  } else {
    cat(msg)
    
    txt <- readLines("stdin", n = 1)
    
  }
  return(txt)
}

txt = typeline("your first message: ")
print(txt)
txt2 = typeline("your second message: ")
print(txt2)

如果我们在第 5 行或第 9 行设置断点,我们可以通过在调试控制台中键入 ###stdin 5 来接收标准输入。见下图。

我希望这能为您指明正确的方向。我能够重现您描述的行为并使用以下功能请求中的指南解决问题:

注意安全。

参考资料:

https://github.com/ManuelHentschel/VSCode-R-Debugger/pull/46

会话信息:

sessionInfo()
List of 13
_names: chr [1:13] "R.version" "platform" "locale" "running" "RNGkind" "basePkgs" ...
_class:"sessionInfo"
__unclass():List of 13
R.version:List of 14
platform:"x86_64-apple-darwin21.1.0 (64-bit)"
locale:"en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8"
running:"macOS Monterey 12.1"
RNGkind: chr [1:3] "Mersenne-Twister" "Inversion" "Rejection"
basePkgs: chr [1:7] "stats" "graphics" "grDevices" "utils" "datasets" "methods" ...
otherPkgs:List of 1
loadedOnly:List of 6
matprod:"default"
BLAS:"/usr/local/Cellar/openblas/0.3.19/lib/libopenblasp-r0.3.19.dylib"
LAPACK:"/usr/local/Cellar/r/4.1.2/lib/R/lib/libRlapack.dylib"
system.codepage:"NULL"
codepage:"NULL"

【讨论】:

    猜你喜欢
    • 2019-06-30
    • 2015-04-09
    • 2017-03-16
    • 2020-07-31
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    相关资源
    最近更新 更多