power BI cannot find function is() in a R script
<h1>Dear all</h1>

<p>I am running the following R script in power BI, with the purpose of getting "data2016" and "df" as output data (both are data frames). With sapply() I am sourcing the function inputFreq() which is a home made function to compute the frequency of an entry in a vector. The function uses is() inside (among other things, see detail below)</p>

<pre><code>setwd("C:/Users/Home/Documents/folder")
data2016 &lt;- read.csv("rawData2016.csv", header = TRUE)
sapply(list.files(pattern="[.]r$", full.names=TRUE), FUN=source)
df &lt;- head(as.data.frame(inputFreq(data2016$var1[1:100])))
</code></pre>

<p>Message Error</p>

<p>After doing Get Data > Other > r script and pasting (all in power BI enviroment), I get the following error</p>

<blockquote>
  <p>Details: "ADO.NET: R script error.
  Error in inputFreq(data2016$var1[1:100]) : 
    could not find function "is"
  Calls: head -> as.data.frame -> inputFreq
  Execution halted</p>
</blockquote>

<p>The function called, inputFreq() has the is() function inside. For info, here´s the function:</p>

<pre><code>inputFreq &lt;- function(x){

  if( is(x, "factor") == TRUE ) {
    x &lt;- as.character(x)
  } else {
    x
  }

  a &lt;- sort(x)
  n &lt;- length(a)
  k &lt;- numeric(n)
  f &lt;- numeric(n)

  # vector k: algoritmo para computar la frecuencia maxima en vector 'a'

  k[1] &lt;- 1
  for (i in 2:n){
    if ( a[i]==a[i-1] ){
      k[i] &lt;- 1 + k[i-1]
    }  else {
      k[i] &lt;- 1
    }

  }

  # vector N: algoritmo para imputar la frecuencia maxima de cada a(i)

  f[n] &lt;- k[n]
  for (j in (n-1):1){
    if ( k[j] &lt; k[j+1] ){
      f[j] &lt;- f[j+1]
    }  else {
      f[j] &lt;- k[j]
    }
  }

  return( cbind( "x" = x, "fr.x" = f[match(x,sort(x))] ) )
}
</code></pre>

<h1>More info</h1>

<p>The function has already performed well in the rstudio environment, the problems seems to be when power BI tries to read the is() function from methods-R.</p>

<h1>Any suggestion? many thanks!!</h1>