HI,
when I run the choose.dir function, a second R application is starting and I
have finally 2 R icon running on my Mac and I have to quit manually the second
R application. Is there a way to quit the second R application automatically?
Thanks,
JPV
Le 29 nov. 2012 à 11:06, Hans-Jörg Bibiko a écrit :
>
> On Nov 29, 2012, at 9:37 AM, Ivan Calandra wrote:
>
>> I have asked on the R list already, but this Mac-list might be more
>> appropriate.
>> I am looking for a function that can choose folders interactively, like
>> choose.dir() on Windows, or like file.choose() does for files.
>>
>> I have found tcltk::tk_choose.dir() but R hangs when I try to do anything
>> and I have to force exit.
>>
>> Jim Holtman proposed to choose a file with file.choose() and then get the
>> path from it using dirname(). This approach would work, but it would be even
>> better if I could choose a folder directly.
>>
>> Duncan Murdoch told me that I could write the equivalent of choose.dir() for
>> MacOS, but it is beyond my reach.
>>
>> Can someone help me on this?
>
> Hi,
>
> for the time being until it will implemented here a quick and 'dirty'
> function:
>
> ---------
> choose.dir <- function() {
> system("osascript -e 'tell app \"R\" to POSIX path of (choose folder
> with prompt \"Choose Folder:\")' > /tmp/R_folder",
> intern = FALSE, ignore.stderr = TRUE)
> p <- system("cat /tmp/R_folder && rm -f /tmp/R_folder", intern = TRUE)
> return(ifelse(length(p), p, NA))
> }
>
> a <- choose.dir()
>
> if(is.na(a)) stop("No folder", call. = F)
>
> print(a)
> ---------
>
> AppleScript displays a "choose folder" GUI; then the chosen path will be
> stored temporarily in the file /tmp/R_folder (since R's system command can't
> run with option 'intern=T' - R will hang); the file content will be outputted
> and stored in the R var "p"; that's it.
>
> Salut,
> --Hans
>
> _______________________________________________
> R-SIG-Mac mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac