1

I was wondering if there are any simple ways to implement user interaction in executing a script in R?

For example if I have a simple function that adds data to an existing dataframe. I would like to let the user decide if additional data should be added or not. Is there a way I could implement this decision process as a command prompt in the console? For example if the user types 'yes' in the console, the adding of data or just a function is executed and if the user types 'no' it is not executed?

Here some example code which adds data_add to data

Input <- file.choose()
data_add <- read.csv(Input, sep=";", header=TRUE, stringsAsFactors=FALSE)
data_new <- rbind(data, data_add)

Has anyone of you implemented such user action in a script and maybe has an easy approach to handling this?

kurdtc
  • 1,551
  • 5
  • 21
  • 39

1 Answers1

1

A quick Google search pointed me to the svDialogs package. Try

library(svDialogs)
okCancelBox("Hello")

it returns TRUE / FALSE and you can use that

ekstroem
  • 5,957
  • 3
  • 22
  • 48