Sign in to follow this  
Followers 0
ValeryVal

AutoR

2 posts in this topic

R is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS.

Home page:

http://www.r-project.org/

International R Users Meeting

useR! 2012, will take place at Vanderbilt University, Nashville Tennessee, USA, June 12-15, 2012

After installation R package you can write AutoIt scripts with help application connector to provide integration solutions R & AutoIt. See more about it here:

http://rcom.univie.ac.at/

download of application connector from here:

http://rcom.univie.ac.at/download/current/statconnDCOM.latest.exe

Scripts:

1. addServer.au3

;=========================================
; create and init an instance of RServerManager on the local machine
dim $oServerManager
dim $ServerCount
dim $oItem
MsgBox(0,"","addServerManager: add server")
if $CmdLine[0] <> 1 then
MsgBox(0,"","addServerManager: create RServerManager")
else
MsgBox(0,"","addServerManager: create RServerManager")
$oServerManager = ObjCreate("RServerManager.ServerPool")
$ServerCount = $oServerManager.Count
MsgBox(0,"","addServerManager: " & $ServerCount & " servers in pool")
MsgBox(0,"","addServerManager: initializing server and adding to pool")
$oServer = ObjCreate("StatConnectorSrv.StatConnector")
$oServer.Init("R")
$oItem = $oServerManager.Add($oServer,$CmdLine[0])
endif

2. dumpServerManager.au3

;===========================
; create and init an instance of RServerManager on the local machine
dim $oServerManager
dim $ServerCount
MsgBox(0,"","dumpServerManager: dump contents of RServerManager")
MsgBox(0,"","dumpServerManager: create RServerManager")
$oServerManager = ObjCreate("RServerManager.ServerPool")
$ServerCount = $oServerManager.Count
MsgBox(0,"","dumpServerManager: " & $ServerCount & " server keys in pool")

3. initServerManager.au3

dim $oServerManager
dim $ServerCount
dim $oServer
MsgBox(0,"","initServerManager: initialize servers")
MsgBox(0,"","initServerManager: create RServerManager")
$oServerManager = ObjCreate("RServerManager.ServerPool")
$ServerCount = $oServerManager.Count
MsgBox(0,"","initServerManager: " & $ServerCount & " servers in pool")
MsgBox(0,"","initServerManager: initializing server and adding to pool")
$oServer = ObjCreate("StatConnectorSrv.StatConnector")
$oServer.Init("R")
$oServerManager.Add($oServer,"R")
MsgBox(0,"","initServerManager: waiting for termination")
MsgBox(4096, "", "The RServerManager will terminate after 10 seconds or select the OK button.", 10)

4. Plot.au3

;create and init an instance of R on the local machine
dim $oServer
$oServer = ObjCreate("StatConnectorSrv.StatConnector")
$oServer.Init("R")
;compute a simple expression (10 random numbers)
$oServer.EvaluateNoReturn("x<-rnorm(10)")
;and plot the result
$oServer.EvaluateNoReturn("plot(x)")

Enjoy...


The point of world view

Share this post


Link to post
Share on other sites



This script is R language monitor.

;===================================================
; AutoRMonitor by Valery Ivanov, 12 April 2012
;===================================================
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $GuiName = "AutoRMonitor © Valery Ivanov, 12 April 2012"
Global $hWnd, $hSGFX = 0
Global $Embeded = 0
Global $SGFXName = "R Graphics: Device 2 (ACTIVE)"
Global $iLeft = 0, $iTop = 0, $iWidth = 1100, $iHeight = 800
Global $iL_Gr = 310, $iT_Gr = 10, $iW_Gr = 780, $iH_Gr = 780
Global $RCode
Global $Font = "Comic Sans MS"
Global $Source, $Result
InitRObjects()
$hWnd = GUICreate($GuiName, $iWidth, $iHeight)
GuiSetFont(8, 600, 0, $Font)
;--------------------------------------------------
$GroupSource = GUICtrlCreateGroup("R code (input):", 10, 10, 280, 400)
$SourceLabel = GUICtrlCreateLabel("R code (input):", 10, 10, 150, 20)
GUICtrlSetColor($SourceLabel,0xaaaaaa)
$RCode = ""
$RCode &= "a <- seq(0.01, 4, by=.01)" & @CrLf
$RCode &= "b<-exp(-(log(a)-0.2)^2/0.4)" & @CrLf
$RCode &= "print(a)" & @CrLf
$RCode &= "print(b)" & @CrLf
$RCode &= 'plot(a,b,main="Log-normal distribution")' & @CrLf
;--------------------------------------------------
$Source = GUICtrlCreateEdit($RCode, 20, 30, 260, 400)
GUICtrlSetColor($Source,0xaaaaaa)
;--------------------------------------------------
$Evaluate = GUICtrlCreateButton("Evaluate", 100, 440, 100, 30)
GUICtrlSetColor($Evaluate,0x0000ff)
;--------------------------------------------------
$GroupResult = GUICtrlCreateGroup("Log (output): ", 10, 480, 280, 300)
$ResultLabel = GUICtrlCreateLabel("Log (output): ", 10, 480, 100, 20)
GUICtrlSetColor($ResultLabel,0x0088aa)
;--------------------------------------------------
$Result = GUICtrlCreateEdit('', 20, 510, 260, 260)
GUICtrlSetColor(-1,0x0088aa)
;--------------------------------------------------
$GroupGraphics = GUICtrlCreateGroup("Graphical device:", $iL_Gr, $iT_Gr, $iW_Gr, $iH_Gr)
$GraphicsLabel = GUICtrlCreateLabel("Graphical device:   ", $iL_Gr, $iT_Gr, 150, 20)
GUICtrlSetColor($GraphicsLabel,0xaaaa00)
GUISetState(@SW_HIDE)
$oStatConnector.EvaluateNoReturn('x<-rnorm(1)')
$oStatConnector.EvaluateNoReturn('plot(x)')
if (Not $Embeded) and IsSGFX() then EmbedSGFX($hWnd,$hSGFX,$iL_Gr+20, $iT_Gr+30, $iW_Gr-40, $iH_Gr-40)
GUISetState()
; Start the main loop
While 1
$Msg = GUIGetMsg()
Select
Case $Msg = $GUI_EVENT_CLOSE
$oStatConnector.Close()
Exit
Case $Msg = $Evaluate
  EvaluateIt()
EndSelect
WEnd
;=======================
func EvaluateIt()
local $SourceContent, $ResultContent, $CodeLine
GUICtrlSetData($Result,"")
$SourceContent = StringStripCR(GUICtrlRead($Source))
$SourceContent = StringSplit($SourceContent,@LF)
For $i = 1 to $SourceContent[0]
  $CodeLine = StringStripWS($SourceContent[$i], 3)
  if Not $CodeLine then ContinueLoop
  $Text = ""
  $ErrorText = ""
  $oStringLogDevice.Text = ""
  $oStatConnector.EvaluateNoReturn($CodeLine)
  $ResultContent = StringStripCR($oStringLogDevice.Text)
  if $ResultContent then
     $ResultContent = GUICtrlRead($Result) & @CRLF & '> ' & $CodeLine & @CRLF & StringReplace($ResultContent,@LF, @CRLF)
;    $ResultContent = GUICtrlRead($Result) & @CRLF & StringReplace($ResultContent,@LF, @CRLF)
     GUICtrlSetData($Result,$ResultContent)
  endif
next
endfunc
;=======================
func IsSGFX()
$hSGFX = WinGetHandle($SGFXName,"")
Sleep (50)
if $hSGFX then return 1
return 0
endfunc
;===========================================
func EmbedSGFX($hWnd,$hView,$iL, $iT, $iW, $iH)
if Not $Embeded then
  DllCall("user32.dll", "long_ptr", "SetWindowLongW", "hwnd", $hView, "int", $GWL_STYLE, "long_ptr", $WS_CHILD + $WS_VISIBLE)
  DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hView, "hwnd", $hWnd)
  DllCall("user32.dll", "bool", "MoveWindow", "hwnd", $hView, "int", $iL, "int", $iT, "int", $iW, "int", $iH, "bool", True)
  $Embeded = 1
endif
endfunc
;===========================================
; Create $oStatConnector, $oStringLogDevice, $oStatConnectorCharacterDevice
func InitRObjects()
Global $oStatConnector, $oStringLogDevice
Local $sCLSID_StatConnector = "{18C8B662-81A2-11D3-9254-00E09812F727}"
Local $sIID_IStatConnector = "{18C8B660-81A2-11D3-9254-00E09812F727}"
Local $sCLSID_StringLogDevice = "{883CDF02-0674-4E6D-878E-3592D75A84A1}"
Local $sIID__StringLogDevice = "{D78C7486-5289-4FE6-B3B0-F74A5294C415}"
$oStatConnector = ObjCreateInterface($sCLSID_StatConnector,$sIID_IStatConnector,Default)
if not IsObj($oStatConnector) then
  MsgBox(0,"","$oStatConnector doesn't created")
  exit
endif
$oStringLogDevice = ObjCreateInterface($sCLSID_StringLogDevice,$sIID__StringLogDevice,Default)
if Not IsObj($oStringLogDevice) then
  MsgBox(0,"","$oStringLogDevice doesn't created")
  exit
endif
$oStatConnector.Init("R")
$oStringLogDevice.BindToServerOutput($oStatConnector)
endfunc

You can evaluate any R-script, get characters output (with error messages) and work with output graphic like this:

post-9395-0-46279000-1335165205_thumb.jp


The point of world view

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0