1

I am trying to build a program, in which a user would enter the desired part of data to plot and the R program would plot it. For example:

n<- function(){
readline(prompt="enter x value to plot")
}
m<- function{
readline(prompt="enter y value to plot")
}
attach(dataset)
plot(unquote(n()), unquote(m()), main="Scatterplot Example", pch=20)

yet this doesnt work, the plot function doesnt recognise the m() and n()? Am I missing somehing?

Thank you.

1
  • How is unquote defined? There is a syntax error in your definition of m. Always report error messages if something "doesn't work". Commented May 24, 2014 at 10:25

1 Answer 1

2

Don't use attach.

n<- function(){
  readline(prompt="enter x value to plot: ")
}
m<- function(){
  readline(prompt="enter y value to plot: ")
}

plotfun <- function(dat) {
  colx <- n()
  coly <- m()
  plot(dat[,colx], dat[,coly], main="Scatterplot Example", pch=20)      
}

if(interactive()) plotfun(dat=iris)
#enter x value to plot: Sepal.Length
#enter y value to plot: Sepal.Width
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, I'm still a noob when it comes to R so this really helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.