Differences between revisions 1 and 2
Revision 1 as of 2009-04-06 18:33:44
Size: 747
Editor: anonymous
Comment:
Revision 2 as of 2009-04-06 18:58:48
Size: 2544
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
=== 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 ====
Line 8: Line 32:
=== APL functions ===
In Dyalog APL
Initialize APL connection to R COM Server.
{{{
     ∇ rinit
[1] '#.R'⎕WC'OleClient' 'StatConnectorSrv.StatConnector'
[2] #.R.Init('R')
     ∇
}}}
Line 11: Line 40:
==== rexec ====

Execute R expression and possibly return the result to APL
Line 12: Line 44:
      )load r2apl
d:\r2apl saved Mon Apr 06 22:10:59 2009
     ∇ 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
     ∇
Line 15: Line 57:
==== RINIT ====
Initialize APL connection to R COM Server.
Line 18: Line 58:
==== rput ====

Put APL array into R
Line 19: Line 62:
)save d:\r2apl
d:\r2apl saved Mon Apr 06 22:10:59 2009
     ∇ {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
     ∇
Line 22: Line 72:

==== 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)
     ∇
}}}

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)