Skip to content
Prev 5589 / 15076 Next

Scripting R

Since this part of the thread is more about Excel/R GUI data copying  
-- the easiest solution is to use clipboard and it's easily scriptable:

* select a table in Excel
* Copy (<Cmd><C>)
* switch to R and run
   read.table(pipe("pbpaste -"),T,"\t")

-- if you didn't include column headers in the paste operation use  
instead:
  read.table(pipe("pbpaste -"),F,"\t")

Clearly, the above is done best with AS:

tell application "Microsoft Excel" to activate
tell application "System Events"
	tell process "Microsoft Excel"
		click menu item "Copy" of menu "Edit" of menu bar 1
	end tell
end tell
tell application "R"
	activate
	cmd "read.table(pipe('pbpaste -'),T,'\\t')"
end tell

(You can actually remove the "Microsoft Excel" parts and it will work  
with any active app such as Numbers)

Bind to a key and all you have to do is to select your table and hit  
that key ...

Cheers,
Simon
On Jan 30, 2009, at 4:53 , Christian Prinoth wrote: