title: invalid 'envir' argument of type 'character' -- in self-defined function with lattice histogram
body: <p>I want a function with parameters such as data name (dat), factor(myfactor), variable names(myvar) to dynamically generate histograms (have to use lattice).</p>
  
  <p>Using IRIS as a minimal example:</p>
  
  <pre><code>data(iris)
  
  
  
  my_histogram &lt;- function(myvar,myfactor,dat){
      listofparam &lt;- c(myvar,myfactor)
      myf &lt;- as.formula(paste("~",paste(listofparam,collapse="|")))
      histogram(myf,
                data=dat,
                main=bquote(paste(.(myvar),"distribution by",.(myfactor),seq=" ")))}
  
  
  
  my_histogram("Sepal.Length","Species","iris") 
  </code></pre>
  
  <p>I also tried do.call as some posts indicated:</p>
  
  <pre><code>my_histogram &lt;- function(myvar,myfactor,dat){
  listofparam &lt;- c(myvar,myfactor)
  myf &lt;- as.formula(paste("~",paste(listofparam,collapse="|")))
  p &lt;- do.call("histogram",
     args = list(myf,
     data=dat))
  print(p)
  
  }
  
  my_histogram("Sepal.Length","Species","iris") 
  </code></pre>
  
  <p>But the error appears: <code>invalid 'envir' argument of type 'character'. I think the program doesn't know where to look for this</code>myf` string. How can I fix this or there's a better way? </p>