Errors generated in Rstudio
You need to convert the elements of corpus to character:

myTokenizer &lt;- function(x, n, n_min) {
  tok &lt;- unlist(tokenize_ngrams(as.character(x), n = n, n_min = n_min))
  M &lt;- matrix(nrow=length(tok), ncol=3, 
              dimnames=list(NULL, c( "gram" , "num.words", "words")))
  M[, 3] &lt;- tok
  M[, 2] &lt;- lengths(strsplit(M[, 3], "\\W+"))  # counts the words
  M[, 1] &lt;- 1:length(tok)
  return(M)
}
res &lt;- tm_map(corp, function (x) myTokenizer(x, n=3, n_min=1))


or apply your function directly without using Corpus:

res &lt;- myTokenizer(x = list("A Sample Text ...", "Lorup ipsum x 12"), n=3, n_min=1))