title: F#, R provider, R package tm and (almost) Ovid example
body: <p>Mind that I am a beginner in F# and R (more so), so possibly point me to RTFM or otherwise ;-)</p>
  
  <p>I have started looking into some text data mining with R, and the package tm.</p>
  
  <p>I have the following script in R, which by the way are very much like the example for Ovid analysis (replace "lgtext" with "txt" for the real example and language="no" with language="lat" to run it with the Ovid example):</p>
  
  <pre><code>library(tm)
  library(SnowballC)
  
  txt &lt;- system.file("texts", "lgtextfull", package = "tm")
  (lgorg &lt;- VCorpus(DirSource(txt, encoding = "UTF-8"), 
            readerControl = list(language = "no")))
  
  lg &lt;- tm_map(lgorg , stripWhitespace)
  </code></pre>
  
  <p>So as a starter I went for using F#, R, Deedle and RPRovider. Deedle I havent used yet so this may be disregarded...</p>
  
  <p>I tried then to write the following F#:</p>
  
  <pre><code>#I "../packages/RProvider.1.0.17/"
  
  #load "RProvider.fsx"
  
  open RProvider
  open RDotNet
  
  open RProvider.``base``
  open RProvider.tm
  open RProvider.openNLP
  open RProvider.SnowballC
  
  let txt = R.system_file("texts", "lgtextfull", package = "tm", lib_loc = null, mustWork=true )
  let lang =  dict [("language", "no":&gt;obj)]
  let readerControl = R.list(lang)
  let dirsource = R.DirSource(txt, encoding = "UTF-8")
  
  let lgorg = R.VCorpus(dirsource, readerControl)
  
  let lg =  R.tm__map(lgorg, R.stripWhitespace)
  </code></pre>
  
  <p>The reason for "extending" the R script so much was for me to understand and make it work.</p>
  
  <p>After some back and forth the above will run and apperently it works and reports in REPL same as in R, with exeption of the last line:</p>
  
  <pre><code>let lg =  R.tm__map(lgorg, R.stripWhitespace)
  </code></pre>
  
  <p>Which gives an error like:</p>
  
  <pre><code>System.Exception: No converter registered for type FSI_0006+lg@81 or any of its base types
     at RProvider.RInteropInternal.convertToR@164.Invoke(String message) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 164
     at Microsoft.FSharp.Core.PrintfImpl.go@523-3[b,c,d](String fmt, Int32 len, FSharpFunc`2 outputChar, FSharpFunc`2 outa, b os, FSharpFunc`2 finalize, FSharpList`1 args, Int32 i)
     at Microsoft.FSharp.Core.PrintfImpl.run@521[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args)
     at Microsoft.FSharp.Core.PrintfImpl.capture@540[b,c,d](FSharpFunc`2 initialize, String fmt, Int32 len, FSharpList`1 args, Type ty, Int32 i)
     at &lt;StartupCode$FSharp-Core&gt;.$Reflect.Invoke@720-4.Invoke(T1 inp)
     at RProvider.RInteropInternal.REngine.SetValue(REngine this, Object value, FSharpOption`1 symbolName) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 274
     at RProvider.RInteropInternal.toR(Object value) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 287
     at RProvider.RInterop.passArg@431(List`1 tempSymbols, Object arg) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 445
     at RProvider.RInterop.argList@452-1.GenerateNext(IEnumerable`1&amp; next) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 453
     at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
     at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
     at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
     at RProvider.RInterop.callFunc(String packageName, String funcName, IEnumerable`1 argsByName, Object[] varArgs) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 450
     at RProvider.RInterop.call(String packageName, String funcName, String serializedRVal, Object[] namedArgs, Object[] varArgs) in c:\Tomas\Public\FSharp.RProvider\src\RProvider\RInterop.fs:line 494
     at &lt;StartupCode$FSI_0006&gt;.$FSI_0006.main@() in C:\Users\helgeu\Documents\Visual Studio 2012\Projects\DisqusAnalyzer\DisqusAnalyzer.Lib\InteractiveSession.fsx:line 81
  Stopped due to error
  </code></pre>
  
  <p>I must admit that I understand nothing of this and google.com doesnt help me either ;-)</p>
  
  <p>Anyone? Any pointers? Should it work? Am I doing it wrong?</p>