title: How to check that a user-defined function works in r?
body: <p>THis is probably a very silly question, but how can I check if a function written by myself will work or not?</p>
  
  <p>I'm writing a not very simple function involving many other functions and loops and was wondering if there are any ways to check for errors/bugs, or simply just check if the function will work. Do I just create a simple fake data frame and test on it?</p>
  
  <p>As suggested by other users in the comment, I have added the part of the function that I have written. So basically I have a data frame with good and bad data, and bad data are marked with flags. I want to write a function that allows me to produce plots as usual (with the flag points) when user sets flag.option to 1, and remove the flag points from the plot when user sets flag.option to 0.</p>
  
  <pre><code>AIR.plot &lt;- function(mydata, flag.option) {
  if (flag.option == 1) {
  par(mfrow(2,1))
  conc &lt;- tapply(mydata$CO2, format(mydata$date, "%Y-%m-%d %T"), mean)
  dates &lt;- seq(mydata$date[1], mydata$date[nrow(mydata(mydata))], length =     nrow(conc))
  plot(dates, conc,
       type = "p",
       col = "blue",
       xlab = "day",
       ylab = "CO2"), error = function(e) plot.new(type = "n")
  barplot(mydata$lines, horiz = TRUE, col = c("red", "blue")) # this is just a   small bar plot on the bottom that specifies which sample-taking line (red or  blue) is providing the samples
  } else if (flag.option == 0) {
  # I haven't figured out how to write this part yet but essentially I want to  remove all
  # of the rows with flags on
  }
  }
  </code></pre>
  
  <p>Thanks in advance, I'm not an experienced R user yet so please help me.</p>