Schmitt, Corinna wrote: > Dear R-experts, > > I have the following function: > > userInput <- function() { > ANSWER <- readline("saving place of the data (example > Z:/Software/test.mat)? ") > x = c(".mat") > endingTest = x %in% ANSWER > print (endingTest) > if (endingTest == "??") > cat ("saving place not accepted\n") > else > cat("Thank you! The current workspace will be stored in: > ",ANSWER,"\n\n") > print(ANSWER ) > } > filename = userInput()
Example: userInput <- function(){ ANSWER <- readline("saving place of the data (example Z:/Software/test.mat)?") endingTest <- length(grep("\\.mat$", ANSWER)) if(!endingTest) cat("saving place not accepted\n") else cat("Thank you! The current workspace will be stored in:", ANSWER, "\n\n") } filename <- userInput() Uwe Ligges > Before I enter the if loop I must test if the text stored in ANSWER has > the pattern ".mat". If yes than endingTest = TRUE else endingTest = > FALSE. > > Another problem is the last codeline. Later on in my program I need the > userinput to ad it to another variable. How can I manage this. I get the > following error message: > > saving place of the data (example Z:/Software/test.mat)? Z:/data.mat > [1] FALSE > Thank you! The current workspace will be stored in: Z:/data.mat > > [1] "Z:/data.mat" > Error in as.vector(x, mode) : cannot change into vector > > > Thanks, Corinna > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.