Hello,
My first enthusiasm got an immediate stopper. After switching the language environment to English and installing the newest version of R (2.40), I was able to calculate 100^2 using the R bundle command R
Console > Execute Selection. Here is the result:
100^2 [1] 0
Now, I wanted to do the following calculation 1/1e-1 and thats the answer: 1/1e-1 Fehler: syntax error
Of course the same calculation leads to the correct result when done in the R console. Does anybody on this list have an idea what happened here? - Obviously I have not entirely got rid of the German localization in R. But is this likely the problem? Now it appears to be an error message generated by R rather than by AppleScript or whatsoever. I am lost.
May be, I need to trash R entirely, which I thought I had. Or is there an alternative way to go (without R). Which bundle should I look up if I wanted to write my own bundle for doing very simple math (I don't know anything about ruby etc)?
JJ
On Dec 8, 2006, at 12:11 PM, Christof Janssen wrote:
May be, I need to trash R entirely, which I thought I had. Or is there an alternative way to go (without R). Which bundle should I look up if I wanted to write my own bundle for doing very simple math (I don't know anything about ruby etc)?
You don't need to know anything about Ruby, in fact the command I mentioned in the previous email computes 1/1e-1 just fine. All you have to do is look up the names of the standard commands in that ruby help page I linked to, so that you know what to call, i.e. that log() is for logarithms log10() for base 10 logarithms etc. If you give us a list of the kind of simple math you want to do, and how ideally you would like to type them in, we can offer a better suggestion I think (though I am fairly certain that the ruby command as it stands will already cover most if not all of them).
JJ
Haris
Thanks this is doing it - Actually I only need to deal with floats using scientific notation and powers, logs, etc., which is all available in ruby (but not quite in the math bundle, where I would have expected it). Are trigonometric functions available in Ruby too? cos(0.5) is not working for me using Ruby.
How would I go to make a decent shortcut for the Execute Line as Ruby command? ^-Shft-E is already used in the Latex bundle - I can certainly use the bundle editor to select another short cut for it, but is this recommended or are there better solutions.
You don't need to know anything about Ruby, in fact the command I mentioned in the previous email computes 1/1e-1 just fine. All you have to do is look up the names of the standard commands in that ruby help page I linked to, so that you know what to call, i.e. that log() is for logarithms log10() for base 10 logarithms etc. If you give us a list of the kind of simple math you want to do, and how ideally you would like to type them in, we can offer a better suggestion I think (though I am fairly certain that the ruby command as it stands will already cover most if not all of them).
JJ
And yes, Haris, 100^2 <> 0. You actually pointed it out - it is not the different functions that cause the problem. There appear many things to go on at the same time, and shame on me, I was not careful enough when reporting to the list. Here is a set of lines that were selected in Textmate and then evaluated through R via the Console command:
100^2 [1] 0
100^2 [1] 10000
1/e-1 Fehler: syntax error
1/1e-1 Fehler: syntax error
1/1e-1 [1] 10
1/e-1 Fehler: objekt "e" nicht gefunden
I made a mistake by typing e-1 instead of 1e-1. This way R could not interpret what I meant. But in addition, the selected region gets somehow corrupted. It seems that the first character is suppressed when transferred to R. Leading to 00 in one case which gives the correct result 0^2=0. When there is an empty space in front of the number it gets transferred completely and 100^2=10000. THis must lead to an error message in case of a 1e-1 at the beginning of a line, because e-1 cannot be interpreted ...
May be this can be confirmed by others, or is it me again?
JJ
Haris
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
If I'm not mistaken to use commands for the console grammer the line needs a leading greater than symbol and space "> ". Doing so gives me the correct answer, the command also inserts this on the next line which is why you see the trailing greater than symbol.
e.g:
100^2
[1] 10000
1/1e-1
[1] 10
See also the help file in the R bundle.
Peter
On 12/8/06, janssen@ccr.jussieu.fr janssen@ccr.jussieu.fr wrote:
Thanks this is doing it - Actually I only need to deal with floats using scientific notation and powers, logs, etc., which is all available in ruby (but not quite in the math bundle, where I would have expected it). Are trigonometric functions available in Ruby too? cos(0.5) is not working for me using Ruby.
How would I go to make a decent shortcut for the Execute Line as Ruby command? ^-Shft-E is already used in the Latex bundle - I can certainly use the bundle editor to select another short cut for it, but is this recommended or are there better solutions.
You don't need to know anything about Ruby, in fact the command I mentioned in the previous email computes 1/1e-1 just fine. All you have to do is look up the names of the standard commands in that ruby help page I linked to, so that you know what to call, i.e. that log() is for logarithms log10() for base 10 logarithms etc. If you give us a list of the kind of simple math you want to do, and how ideally you would like to type them in, we can offer a better suggestion I think (though I am fairly certain that the ruby command as it stands will already cover most if not all of them).
JJ
And yes, Haris, 100^2 <> 0. You actually pointed it out - it is not the different functions that cause the problem. There appear many things to go on at the same time, and shame on me, I was not careful enough when reporting to the list. Here is a set of lines that were selected in Textmate and then evaluated through R via the Console command:
100^2 [1] 0
100^2 [1] 10000
1/e-1 Fehler: syntax error
1/1e-1 Fehler: syntax error
1/1e-1 [1] 10
1/e-1 Fehler: objekt "e" nicht gefunden
I made a mistake by typing e-1 instead of 1e-1. This way R could not interpret what I meant. But in addition, the selected region gets somehow corrupted. It seems that the first character is suppressed when transferred to R. Leading to 00 in one case which gives the correct result 0^2=0. When there is an empty space in front of the number it gets transferred completely and 100^2=10000. THis must lead to an error message in case of a 1e-1 at the beginning of a line, because e-1 cannot be interpreted ...
May be this can be confirmed by others, or is it me again?
JJ
Haris
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
[...]
There are pro and cons to perl/ruby/php/R/... By myself I'm using perl and R ;)
But I looked at the R-Bundle and I wrote a command (in bash) which executes R directly in script mode à la
R --no-save --silent <<< "$TASK" 2>/dev/null
There is no need to use Applescript or running R.app in beforehand to calculate some tiny things, pasting results to and fro...
This command takes the Selection or Line, executes this by using R, and replaces the Selection with the result without leading '[]'. If an error occurs or 'Inf' or 'NaN' is returned it shows a tooltip.
Please note, this is only a fast written script as a basis for discussions, and can modified in any direction. I tried it out and things like 1/1e-1, 100^2, mean(c(1:20)), print("HALLO") worked fine. Things like 'matrix(c(1:20),nrow=4) also work but without leading row numbers of course. Warnings and error messages are suppressed.
Maybe this could be an approach to solve this problem with R.
An other approach could be the rinterp
http://wiki.r-project.org/rwiki/doku.php?id=developers:rinterp
I use this on my Linux server and it works perfectly. With the help of this you can write raw R source code within a command in TM and executes this like perl, ruby, python etc.
The only thing I don't know whether it is possible to compile this on a Mac. I can remember that you have to compile R with shared libraries in beforehand, but I'm not quite sure about that.
-Hans
---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Dec 8, 2006, at 3:49 PM, Hans-Joerg Bibiko wrote:
But I looked at the R-Bundle and I wrote a command (in bash) which executes R directly in script mode à la
R --no-save --silent <<< "$TASK" 2>/dev/null
There is no need to use Applescript or running R.app in beforehand to calculate some tiny things, pasting results to and fro...
This command takes the Selection or Line, executes this by using R, and replaces the Selection with the result without leading '[]'. If an error occurs or 'Inf' or 'NaN' is returned it shows a tooltip.
Please note, this is only a fast written script as a basis for discussions, and can modified in any direction. I tried it out and things like 1/1e-1, 100^2, mean(c(1:20)), print("HALLO") worked fine. Things like 'matrix(c(1:20),nrow=4) also work but without leading row numbers of course. Warnings and error messages are suppressed.
Maybe this could be an approach to solve this problem with R.
This was my first approach to this too. The problem is that this is relatively slow, because it has to load R each time, and that does take up time. The interpreter sounds like a better idea, but it doesn't work out of the box. (well, I guess we don't even know if we can make it work at all yet ;) ). There is an approach that is relatively doable but had technical problems. We can start an R process in the background, and communicate to it via named pipes, which you can think of if you like as files on the hard drive that TM would write to and R would read from. This would be reasonably fast. The problem we are encountering, so to speak, is that this would mean a shared R environment for all your R work. So imagine you are working on three different R projects, on different R windows. They might be defining conflicting varialbes and messing up each other's computations, if they are sent to the same R process. So this adds a considerable amount of details that need to be overcome.
An other approach could be the rinterp
http://wiki.r-project.org/rwiki/doku.php?id=developers:rinterp
I use this on my Linux server and it works perfectly. With the help of this you can write raw R source code within a command in TM and executes this like perl, ruby, python etc.
The only thing I don't know whether it is possible to compile this on a Mac. I can remember that you have to compile R with shared libraries in beforehand, but I'm not quite sure about that.
-Hans
Haris
Quoting Charilaos Skiadas skiadas@hanover.edu:
On Dec 8, 2006, at 3:49 PM, Hans-Joerg Bibiko wrote:
But I looked at the R-Bundle and I wrote a command (in bash) which executes R directly in script mode à la
R --no-save --silent <<< "$TASK" 2>/dev/null
[...]
This was my first approach to this too. The problem is that this is relatively slow, because it has to load R each time, and that does take up time. The interpreter sounds like a better idea, but it doesn't work out of the box. (well, I guess we don't even know if we can make it work at all yet ;) ).
Well, this solution is good for tiny calculations. The speed, well, depends on the machine. Tiny things are done in less than a second.
There is an approach that is relatively doable but had technical problems. We can start an R process in the background, and communicate to it via named pipes, which you can think of if you like as files on the hard drive that TM would write to and R would read from. This would be reasonably fast. The problem we are encountering, so to speak, is that this would mean a shared R environment for all your R work. So imagine you are working on three different R projects, on different R windows. They might be defining conflicting varialbes and messing up each other's computations, if they are sent to the same R process. So this adds a considerable amount of details that need to be overcome.
This sounds good, but you mentioned the problems. I will sleep about that.
But, if you are running several R sessions with complex tasks, well, then I have an humble question: Why do you are using TM for that? You want to control all R sessions with TM?
If I understood the starting point correctly one is looking for a solution to solve 'easy' mathematical tasks with R.
-Hans
---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Dec 8, 2006, at 5:18 PM, Hans-Joerg Bibiko wrote:
But, if you are running several R sessions with complex tasks, well, then I have an humble question: Why do you are using TM for that? You want to control all R sessions with TM?
Because TM is much better at editing code than the crappy R.app interface. Ok, it's not too bad, but it's not TM.
If I understood the starting point correctly one is looking for a solution to solve 'easy' mathematical tasks with R.
Correct. Well, I think the starting point was just to solve easy mathematical tasks, I don't think R was a requirement. It was just what the OP was using for the task atm.
-Hans
Haris
But, if you are running several R sessions with complex tasks, well, then I have an humble question: Why do you are using TM for that? You want to control all R sessions with TM?
Hans,
I THINK that what Haris meant was that you may have the WORKSPACE from the different running R sessions getting mixed up.. Whereby potentially some variables are being created by one session and wrongly evaluated by another session that thinks they are part of that session. I for one am one of those that frequently runs 3 instances of R all from TM - sometimes (almost) simultaneously: the R version; the Sweave version; and the Console version (this more for the simple one off calculations say as I work in my latex/Sweave document - infact, at times the calculation has nothing to do with the work - but someone calls while I am in the middle of work & presents a set of figures - eg a debt that I quickly need to work out). So I would care that the potential mess up that Haris mentions does not occur because of something lying around/defined in the workspace by one or the other of these different environments. And yes, I know that I can use the maths bundle for some calculation, but I for one feel comfortable using R even for these since I can save the variables eg if I am doing sample size calculations.
danstan
But, if you are running several R sessions with complex tasks, well, then I have an humble question: Why do you are using TM for that? You want to control all R sessions with TM?
Hans,
I THINK that what Haris meant was that you may have the WORKSPACE from the different running R sessions getting mixed up.. Whereby potentially some variables are being created by one session and wrongly evaluated by another session that thinks they are part of that session. I for one am one of those that frequently runs 3 instances of R all from TM - sometimes (almost) simultaneously: the R version; the Sweave version; and the Console version (this more for the simple one off calculations say as I work in my latex/ Sweave document - infact, at times the calculation has nothing to do with the work - but someone calls while I am in the middle of work & presents a set of figures - eg a debt that I quickly need to work out). So I would care that the potential mess up that Haris mentions does not occur because of something lying around/defined in the workspace by one or the other of these different environments. And yes, I know that I can use the maths bundle for some calculation, but I for one feel comfortable using R even for these since I can save the variables eg if I am doing sample size calculations.
danstan
Quoting Charilaos Skiadas skiadas@hanover.edu:
This was my first approach to this too. The problem is that this is relatively slow, because it has to load R each time, and that does take up time. The interpreter sounds like a better idea, but it doesn't work out of the box. (well, I guess we don't even know if we can make it work at all yet ;) ). There is an approach that is relatively doable but had technical problems. We can start an R process in the background, and communicate to it via named pipes, which you can think of if you like as files on the hard drive that TM would write to and R would read from. This would be reasonably fast. The problem we are encountering, so to speak, is that this would mean a shared R environment for all your R work. So imagine you are working on three different R projects, on different R windows. They might be defining conflicting varialbes and messing up each other's computations, if they are sent to the same R process. So this adds a considerable amount of details that need to be overcome.
Well, I tried it to communicate with R via named pipes. It works quite good but one thing is tricky.
I created a fifo r_pipe
Then I started R via
R --slave <r_pipe >result.txt
After that I wrote in an other bash shell:
echo "2+3" >r_pipe
OK. In result.txt you can see [1] 5. But my R job was cancelled. I didn't find out a way to avoid this canceling.
Then I checked the following hack. I call 'R --slave <r_pipe >result.txt' in a loop. Before R is cancelled I saved the workspace and reload that workspace with the new start. This works but if you have a large workspace it takes time.
The point is: how to avoid cancelling R??
My approach would be to start a new R session which is bounced to a named pipe. By doing so you could write in TM the line
3+4 >r_pipe17
for the 17th session I started.
Any ideas?
@hadley: Of course 'R --slave ...' simplifes the script.
-Hans
---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Dec 10, 2006, at 10:09 AM, Hans-Joerg Bibiko wrote:
The point is: how to avoid cancelling R??
My approach would be to start a new R session which is bounced to a named pipe. By doing so you could write in TM the line
No no the way to go is to create a deamon program in ruby or something. It runs R and makes sure to keep it open. We sort of had gotten it working (well, Allan had gotten it working, I could barely understand what was going on). The attached file might get you started.
3+4 >r_pipe17
for the 17th session I started.
Any ideas?
Haris
But I looked at the R-Bundle and I wrote a command (in bash) which executes R directly in script mode à la
R --no-save --silent <<< "$TASK" 2>/dev/null [...]
Here is an improved version.
Changes: - do not insert a NEWLINE after the selection - if the result is complex meaning two or more lines the output is the same like in R; now you can insert e.g. this 'matrix(c(1:20),nrow=4)' correctly or if you want '?print'
-Hans
---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Dec 8, 2006, at 2:39 PM, janssen@ccr.jussieu.fr wrote:
Thanks this is doing it - Actually I only need to deal with floats using scientific notation and powers, logs, etc., which is all available in ruby (but not quite in the math bundle, where I would have expected it). Are trigonometric functions available in Ruby too? cos(0.5) is not working for me using Ruby.
How would I go to make a decent shortcut for the Execute Line as Ruby command? ^-Shft-E is already used in the Latex bundle - I can certainly use the bundle editor to select another short cut for it, but is this recommended or are there better solutions.
No no you should not be using the "Executre Line as Ruby" command. You should instead create a new command with the text I had pasted, and then Kevin corrected. You create a new command via the Bundle editor. The command I and Kevin are talking about doesn't just execute the current line in Ruby. It "imports" the Math "module", which means that instead of having to type Math.cos(0.2) you can type simply cos (0.2). That's why cos(0.2) was not working for you via the Execute Line as Ruby command, while Math.cos(0.2) would have worked.
As far as shortcut goes, in general a lot of ctrl+ combinations are available, they are reserved for user use. Of course you can also assign it the same shortcut as the math calculation commands, and then you'll be seeing it as an extra option in the popup.
You don't need to know anything about Ruby, in fact the command I mentioned in the previous email computes 1/1e-1 just fine. All you have to do is look up the names of the standard commands in that ruby help page I linked to, so that you know what to call, i.e. that log() is for logarithms log10() for base 10 logarithms etc. If you give us a list of the kind of simple math you want to do, and how ideally you would like to type them in, we can offer a better suggestion I think (though I am fairly certain that the ruby command as it stands will already cover most if not all of them).
JJ
And yes, Haris, 100^2 <> 0. You actually pointed it out - it is not the different functions that cause the problem. There appear many things to go on at the same time, and shame on me, I was not careful enough when reporting to the list. Here is a set of lines that were selected in Textmate and then evaluated through R via the Console command:
I made a mistake by typing e-1 instead of 1e-1. This way R could not interpret what I meant. But in addition, the selected region gets somehow corrupted. It seems that the first character is suppressed when transferred to R. Leading to 00 in one case which gives the correct result 0^2=0. When there is an empty space in front of the number it gets transferred completely and 100^2=10000. THis must lead to an error message in case of a 1e-1 at the beginning of a line, because e-1 cannot be interpreted ...
May be this can be confirmed by others, or is it me again?
Ah you are using the R Console command. That requires you are in "console mode", which means your line should start with ">" followed by a space, in addition to scope requirements. So the command kills the first two characters before sending the input to R. It's the killing of those characters that is causing the problem in your case I'd bet.
In general right now all these R commands are a bit of a really really ugly hack. Because of the complete lack of applescript support from the part of R.app, we have to use system events, which means that, in order to find out the result of the computation, we have to "tell the system to tell us the contents of the scroll view of the first window of the application whose name is R.app", or something ridiculous close to that. We have to do this before we send the input to R.app. Then we have to send the input to R, and then we have to do the same thing, and read the new output. Finally, we have to take the difference of the two outputs to see what the new stuff that was added is. As you can imagine, this is completely ridiculous and should be avoided as much as possible, until we find a better way to talk to R. That's mainly why I am strongly suggesting using some other way.
JJ
Haris
On Dec 8, 2006, at 12:11 PM, Christof Janssen wrote:
Here is the result: 100^2 [1] 0
Btw, this doesn't look too right ;)
The ^ in the ruby case would have to be **, but all the other operations are normal.
Haris