[R-SIG-Mac] drag & drop on R icon not changing directory

David Winsemius dwinsemius at comcast.net
Tue Nov 6 19:45:23 CET 2012


On Nov 6, 2012, at 9:48 AM, Prof Brian Ripley wrote:

> On 06/11/2012 17:30, David Winsemius wrote:
>> 
>> On Nov 6, 2012, at 6:05 AM, Ken Knoblauch wrote:
>> 
>>> Hi,
>>> 
>>> just noticed this in R version 2.15.2 Patched (2012-11-04 r61084),
>>> that dragging a file onto the R icon when starting a session is not
>>> changing to the directory of the file.
>>> 
>>> sessionInfo()
>>> R version 2.15.2 Patched (2012-11-04 r61084)
>>> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>>> 
>>> locale:
>>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>> 
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>> 
>>> Thanks.
>> 
>> I'm a bit puzzled by this. I never in the past expected that the working directory would be changed when doing this. Are you saying I should have expected the working directory to change when a file icon was dragged on top of the R-dock icon? What should I be reading that I missed?
> 
> The MacOSX FAQ?  But that is not a very reliable document (less unreliable in 2.15.2 than in the recent past).
> 
> http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Drag-_0026-drop
> 
> seems to say the directory is changed if a directory is dropped, but not say so for other types of files (and it may depend on the type of file).
> 
> Works as documented for directories, at least.
> 

That's what I see for for directories. The other behavior (in the GUI) I see:

After dragging an R-source file  to the R64 dock icon from the directory: "/Users/davidwinsemius/Documents/R-code"
>  getwd()
[1] "/Users/davidwinsemius"

So no change in the working directory. The GUI displays the code in an editing window. (That second behavior for GUI can be specified in Preferences settings.) Described in R for MacOSX FAQ 4.6.0.1 Startup: http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Startup

> load("/Users/davidwinsemius/Documents/MASS/data/abbey.rda")
> getwd()
[1] "/Users/davidwinsemius"

So no change in the directory with drag-dropping an .rda file. Described in 6.3 Finder actions: http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Finder-actions

Then drag-dropping a directory (after what seemed like an unexpected amount of rainbow-spinnner activity)

> setwd("/Users/davidwinsemius/Documents/R-code")
[Workspace restored from /Users/davidwinsemius/Documents/R-code/.RData]

So not only is the working directory changed, but a .RData file was sought out and "restored". Described in MacOSX FAQ 4.4.8 "Drag & drop". Apparently the data-objects are loaded along side the current workspace objects. There is a line that says: "Whether the file is opened or sourced is specified by a Preference setting in the StartUp Preference Pane."

So the Startup Preference checkbox setting "always apply" for Initial Working Directory can be set to override this behavior. I was not able to produce behavior that were not described once I did a "search-scan" through the FAQ with the term "drag"


-- 
David Winsemius, MD
Alameda, CA, USA



More information about the R-SIG-Mac mailing list