Last month I asked how to select some text and press a keyboard shortcut that would send the selected text to R app: http://lists.macromates.com/textmate/2014-March/037158.html
This is working excellently well. I¹m interested in extending this, but cannot figure out how to set it up.
Lets say I have this code:
summary(lm(mpg ~ drat + hp, mtcars))
How can select 'mtcars¹ and hp¹ simultaneously, press a keyboard shortcut and run this code in R app:
mtcars$hp
Similarly, in this code:
ddply(mtcars, .(cyl), summarise, mean(mpg))
How can select 'mtcars¹ and mpg¹ simultaneously, press a keyboard shortcut and run this code in R app:
mtcars$mpg
Thanks Ross
Hi Ross,
On 03 Apr 2014, at 21:05, Ross Ahmed rossahmed@googlemail.com wrote:
Lets say I have this code:
summary(lm(mpg ~ drat + hp, mtcars))
How can select 'mtcars’ and ‘hp’ simultaneously, press a keyboard shortcut and run this code in R app:
mtcars$hp
unfortunately up to now it would be a stony way to achieve this - due to TM's "alpha" status I think. The point here is that if you have more than one selection the TM variable "TM_SELECTION" holds "only" the information about the line number-start of selection:length of selection. In addition to that - even if all selections are in the SAME line - TM 2.0 doesn't set the TM variable "TM_CURRENT_LINE". This would mean if you want to get the actual content of the selections you have to calculate the contents by yourself. This could be done maybe by: - set the tmCommand's "Input:" to "Document" - get the entire document content - iterate through each selection in "TM_SELECTION" by - - get line number -> get the content of the line based on the document's content - - get start and length of your selection - - get the substring (content) for each selection - concatenate the selections by "$" to cmd - send cmd to R.app
Kind regards, Hans
If you wrote it as
summary(lm(mpg ~ drat + hp, data = mtcars))
then I think it is more doable.
the command could then run with just 1 carat specifying the variable, with the content of the line allowing deduction of mtcars as the data) Return data$var to the R console is then straightforward
Lets say I have this code:
summary(lm(mpg ~ drat + hp, mtcars))
How can select 'mtcars’ and ‘hp’ simultaneously, press a keyboard shortcut and run this code in R app:
mtcars$hp
unfortunately up to now it would be a stony way to achieve this - due to TM's "alpha" status I think. The point here is that if you have more than one selection the TM variable "TM_SELECTION" holds "only" the information about the line number-start of selection:length of selection. In addition to that - even if all selections are in the SAME line - TM 2.0 doesn't set the TM variable "TM_CURRENT_LINE". This would mean if you want to get the actual content of the selections you have to calculate the contents by yourself. This could be done maybe by:
- set the tmCommand's "Input:" to "Document"
- get the entire document content
- iterate through each selection in "TM_SELECTION" by
- get line number -> get the content of the line based on the document's content
- get start and length of your selection
- get the substring (content) for each selection
- concatenate the selections by "$" to cmd
- send cmd to R.app