'How to get a user input in command prompt and pass it to R

I am trying to use

var <- as.numeric(readline(prompt="Enter a number: "))

and later use this in a calculation.

It works fine when running in RStudio but I need to be able to pass this input from the command line in Windows 10 I am using a batch file with a single line

Rscript.exe "C:\My Files\R_scripts\my_script.R"

When it gets to the user input part it freezes and it doesn't provide expected output.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source