Hi R-helpers, I must use WinXP at work, and I'm missing a particular feature that's available in R on my Mac at home... In WinXP I would like to launch R by dragging and releasing a text file on top of the R shortcut on my desktop. Then, I would like the working directory to be automatically set to the location of that text file. That's what works in MacOS, but I can't figure out if it's possible in WinXP. Any ideas? I'd appreciate it... Thanks, Mark Na PS What I do now is make a new R shortcut for each project, store that shortcut in the directory containing that project's datafiles and R programs (which are in text files), and set the "Start in" value to that directory...but this has to be set up uniquely for each project...
Set working directory by dragging text file onto R shortcut? [WinXP, unfortunately]
4 messages · Mark, Duncan Murdoch, Gabor Grothendieck
There are a several possibilities using batchfiles whose home page is at: http://batchfiles.googlecode.com When on that home page note that there are different versions of these utilities for XP and Vista. There are two utilities that could be used. Description is for Vista so for XP you may have to vary it slightly. 1. RguiStart.bat is a batch file that starts R interpreting its first argument as the folder in which to start R (or if its an .Rdata file then it interprets it as the .Rdata file to start R with). The main reason for its existence is so that you can place it in your SendTo folder. On Vista do this: copy RguiStart.bat %APPDATA%\Microsoft\Windows\SendTo Then, on Vista, when you are in Windows Explorer you can right click on any folder in your user area and choose SendTo. From the SendTo menu choose RGuiStart.bat to start up R in that folder. If you right click on an .Rdata file rather than a folder then R will start up with that file loaded (although in that case its probably easier to just double click the .Rdata file provided you have file type associations set up -- if you don't then the RguiStart.bat will provide an alternative). 2. Rgui.bat is a batch file that starts up R. Just shift right click a folder in Windows Explorer and choose Open Command Window Here and then when the command window opens enter Rgui assuming you have placed Rgui.bat somewhere on your path. Note that Rgui.bat and RguiStart.bat are actually the same file just renamed. When it runs it uses the name by which it was called to determine what to do. The files have no dependencies and find R by looking in the registry so when you install a new version of R they continue to work without any change (because installing a new version of R updates the registry).
On Mon, May 11, 2009 at 6:30 PM, Mark Na <mtb954 at gmail.com> wrote:
Hi R-helpers, I must use WinXP at work, and I'm missing a particular feature that's available in R on my Mac at home... In WinXP I would like to launch R by dragging and releasing a text file on top of the R shortcut on my desktop. Then, I would like the working directory to be automatically set to the location of that text file. That's what works in MacOS, but I can't figure out if it's possible in WinXP. Any ideas? I'd appreciate it... Thanks, Mark Na PS What I do now is make a new R shortcut for each project, store that shortcut in the directory containing that project's datafiles and R programs (which are in text files), and set the "Start in" value to that directory...but this has to be set up uniquely for each project...
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On 11/05/2009 6:30 PM, Mark Na wrote:
Hi R-helpers, I must use WinXP at work, and I'm missing a particular feature that's available in R on my Mac at home... In WinXP I would like to launch R by dragging and releasing a text file on top of the R shortcut on my desktop. Then, I would like the working directory to be automatically set to the location of that text file. That's what works in MacOS, but I can't figure out if it's possible in WinXP. Any ideas? I'd appreciate it... Thanks, Mark Na PS What I do now is make a new R shortcut for each project, store that shortcut in the directory containing that project's datafiles and R programs (which are in text files), and set the "Start in" value to that directory...but this has to be set up uniquely for each project...
You can execute a script on startup as follows:
1. Put the script into a file somewhere, e.g. c:/temp/test.R
2. Edit your shortcut to R to set the command to something like this:
path\to\Rgui.exe R_PROFILE_USER=c:/temp/test.R --args
Now your script will execute on startup, and you can have it change
directory, load a file, whatever you want. For example, this changes
directory to the directory of the file dropped on the shortcut, then
opens the file for editing:
Contents of test.R:
filename <- commandArgs(TRUE)
if (length(filename)) {
setwd(dirname(filename))
utils::file.edit(filename)
}
You can make it as involved as you like, e.g. looking at the file
extension to determine what to do with it, etc.
Duncan Murdoch
One additional way to use this is to place RGuiStart.bat on your desktop and then you can drag a folder to it. On Mon, May 11, 2009 at 7:14 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
There are a several possibilities using batchfiles whose home page is at: http://batchfiles.googlecode.com When on that home page note that there are different versions of these utilities for XP and Vista. There are two utilities that could be used. ?Description is for Vista so for XP you may have to vary it slightly. 1. RguiStart.bat is a batch file that starts R interpreting its first argument as the folder in which to start R (or if its an .Rdata file then it interprets it as the .Rdata file to start R with). ?The main reason for its existence is so that you can place it in your SendTo folder. ?On Vista do this: ?copy RguiStart.bat %APPDATA%\Microsoft\Windows\SendTo Then, on Vista, when you are in Windows Explorer you can right click on any folder in your user area and choose SendTo. ?From the SendTo menu choose RGuiStart.bat to start up R in that folder. ?If you right click on an .Rdata file rather than a folder then R will start up with that file loaded (although in that case its probably easier to just double click the .Rdata file provided you have file type associations set up -- if you don't then the RguiStart.bat will provide an alternative). 2. Rgui.bat is a batch file that starts up R. ?Just shift right click a folder in Windows Explorer and choose Open Command Window Here and then when the command window opens enter Rgui assuming you have placed Rgui.bat somewhere on your path. Note that Rgui.bat and RguiStart.bat are actually the same file just renamed. When it runs it uses the name by which it was called to determine what to do. The files have no dependencies and find R by looking in the registry so when you install a new version of R they continue to work without any change (because installing a new version of R updates the registry). On Mon, May 11, 2009 at 6:30 PM, Mark Na <mtb954 at gmail.com> wrote:
Hi R-helpers, I must use WinXP at work, and I'm missing a particular feature that's available in R on my Mac at home... In WinXP I would like to launch R by dragging and releasing a text file on top of the R shortcut on my desktop. Then, I would like the working directory to be automatically set to the location of that text file. That's what works in MacOS, but I can't figure out if it's possible in WinXP. Any ideas? I'd appreciate it... Thanks, Mark Na PS What I do now is make a new R shortcut for each project, store that shortcut in the directory containing that project's datafiles and R programs (which are in text files), and set the "Start in" value to that directory...but this has to be set up uniquely for each project...
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.