Differences between revisions 2 and 3
Revision 2 as of 2009-04-06 18:58:48
Size: 2544
Editor: anonymous
Comment:
Revision 3 as of 2009-04-06 19:01:23
Size: 2528
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
Line 12: Line 13:
     )obs ⍝ new object R is created        )obs ⍝ new object R is created
Line 17: Line 18:
      1 rexec 'mean(y)' ⍝ calculate mean value in R        1 rexec 'mean(y)' ⍝ calculate mean value in R
Line 31: Line 32:
Initialize APL connection to R COM Server.
Line 32: Line 34:
Initialize APL connection to R COM Server.
Line 39: Line 40:
==== rexec ====
Execute R expression and possibly return the result to APL
Line 40: Line 43:
==== rexec ====

Execute R expression and possibly return the result to APL
Line 57: Line 57:
==== rput ====
Put APL array into R
Line 58: Line 60:
==== rput ====

Put APL array into R
Line 72: Line 71:
==== rget ====
Get R variable (matrix or vector) to APL
Line 73: Line 74:
==== rget ====

Get R variable (matrix or vector) to APL

Interface to R

Using COM Server

Installation

  1. Install R statistical environment from www.r-project.org

  2. Install R package rcproxy from //cran.rakanu.com/bin/windows/contrib/2.8/rscproxy_1.2-0.zip

  3. Install DCOM Server from //cran.r-project.org/contrib/extra/dcom/

Sample APL Session

     )load r2apl
d:\r2apl saved Mon Apr 06 22:10:59 2009
     rinit ⍝ initialize connection to R COM server
     )obs  ⍝ new object R is created
R
      +x←10?100         ⍝ random numbers in APL
14 76 46 54 22 5 68 94 39 52
      'y'rput x         ⍝ send them to R
      1 rexec 'mean(y)' ⍝ calculate mean value in R
47
      +/x÷⍴x            ⍝ the same in APL
47
      y←rget 'y'        ⍝ get variable y from R to APL
      x≡y               ⍝ compare with original x
1
      y←?100 6⍴2*30     ⍝ generate another random set
      y←(+/y÷2*30)÷6
      'y'rput y         ⍝ put it in R
      rexec 'hist(y)'   ⍝ call R function to plot histogram

Dyalog APL functions

rinit

Initialize APL connection to R COM Server.

     ∇ rinit
[1]    '#.R'⎕WC'OleClient' 'StatConnectorSrv.StatConnector'
[2]    #.R.Init('R')

rexec

Execute R expression and possibly return the result to APL

     ∇ a←{r}rexec exp
[1]    ⍝ Execute R expression and possibly return the result
[2]    ⍝R: R expression ('char')
[3]    ⍝L: if 1, then return the result
[4]    ⍎(0=⎕NC'r')/'r←0'
[5]    a←⍬
[6]    :If r
[7]        a←#.R.Evaluate(exp)
[8]    :Else
[9]        #.R.EvaluateNoReturn(exp)
[10]   :EndIf

rput

Put APL array into R

     ∇ {m}rput a;x1
[1]    ⍝ Put APL array into R
[2]    ⍝R-name of variable to export from APL
[3]    ⍝L-name of variable to create in R
[4]    ⍎(0=⎕NC'm')/'m←''x''' ⍝ Default name is x
[5]    m←,⊂m
[6]    a←,⊂a
[7]    #.R.SetSymbol(m,a) ⍝ put var a into R with name m

rget

Get R variable (matrix or vector) to APL

     ∇ r←rget name;rho;Re;Im;⎕ML
[1]   ⍝ Get R variable (matrix or vector) to APL
[2]   ⍝R-name of variable to import ('char')
[3]    ⎕ML←3
[4]    r←#.R.GetSymbol(name)

r2apl (last edited 2017-02-16 18:39:27 by KaiJaeger)