For example, if I need that the user specifies the number of rows and columns of a matrix:
PROMPT: Number of rows?:
USER INPUT: [a number]
I need that R 'waits' for the input. Then save [a number] into a variable v1. Next,
PROMPT: Number of columns?:
USER INPUT: [another number]
Also save [another number] into a variable v2. At the end, I will have two variables (v1, v2) that will be used in the rest of the code.
"readline" only works for one input at a time. I can't run the two lines together
v1 <- readline("Number of rows?: ")
v2 <- readline("Number of columns?: ")
Any ideas or suggestions?
Thank you in advance
You can combine those statements into a clause:
{ v1 <- readline("Number of rows?: "); v2 <- readline("Number of columns?: ") }
Or generally, make them into a function:
readlines <- function(...) {
lapply(list(...), readline)
}
readlines("Number of rows?: ", "Number of columns?: ")
You may find useful the tkentry function in package tcltk (for more examples see here). There is also a guiDlg function in package svDialogs
library(svDialogs)
display(guiDlg("SciViews-R", "My first dialog box with SciViews-R"))
Check this page for more..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With