Reputation: 5450
I am debugging an R script in VSC. This script logs to Google API, so it prompts the user to select a pre-authorized account from a menu:
1: [email protected]
2: [email protected]
The problem is that after entering the menu option (1
, in my case) and entering Enter
in the DEBUG CONSOLE
, the script doesn't continue even when the input is accepted and displayed in the console.
You can see an image of the DEBUG CONSOLE here:
As you can see, nothing happens after entering a menu option (when I debug this code in PyCharm, the script does continue after entering 1
)
Upvotes: 0
Views: 259
Reputation: 8666
The VSCode-R-Debugger starts and controls R programs by sending input to stdin of the child process. To take input in debug mode you have to enter the data in the debug console and prefix it with ###stdin. The feature is described via the following Github request and marked as resolved. I was able to use the following example code to confirm the solution is current and works as described:
#!/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)
If we set a breakpoint on lines 5 or 9, we can then receive stdin input by typing ###stdin 5 in the debug console. See the image below.
I am hoping this points you in the right direction. I was able to reproduce the behavior you describe and address the problem using the guidance in the feature request below:
Take care and stay safe.
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"
Upvotes: 1