kurdtc
kurdtc

Reputation: 1621

R: User interaction in console for executing function in R

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?

Upvotes: 1

Views: 416

Answers (1)

ekstroem
ekstroem

Reputation: 6151

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

library(svDialogs)
okCancelBox("Hello")

it returns TRUE / FALSE and you can use that

Upvotes: 1

Related Questions