How can i replicate this in Linux: source(file.choose()) I've tried source(tkgetOpenFile()) but with no luck
Have not found a way to do this either, or in any case it has been buggy. It
would depend on the file manager you have installed. But, you're using
Linux! The path and working directory are supposed to be half the fun. Maybe
create an R folder in /home to keep your files and adjust your R terminal
settings so that organization and dir() will get you what you want.
Hope that helps,
Ken Hutchison
On Nov 28, 2554 BE, at 6:07 AM, Ana <rrasterr at gmail.com> wrote:
> How can i replicate this in Linux:
> source(file.choose())
>
>
> I've tried source(tkgetOpenFile()) but with no luck
>
> ______________________________________________
> 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 Mon, 28-Nov-2011 at 12:07PM +0100, Ana wrote:
|> How can i replicate this in Linux:
|> source(file.choose())
|>
As the Mac people used to say ungrammatically: Think Different.
There are many ways of using Linux that can't be done in Windows and
we know nothing of your setup, so it's not obvious what's most
appropriate for you. Maybe something like the following:
Start R from the directory you wish to use, preferably using ESS which
will give you a separate Emacs window where you run your R commands.
Otherwise open a second tab in your terminal window (which will
automatically be the same directory). A Terminal window will thus be
available where you can list your files, say with ls or ll. Paste the
file name (using only the mouse) into your R command window.
Takes lots of words to describe, but very easy to do. There are many
variations on that idea.
HTH
--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
___ Patrick Connolly
{~._.~} Great minds discuss ideas
_( Y )_ Average minds discuss events
(:_~*~_:) Small minds discuss people
(_)-(_) ..... Eleanor Roosevelt
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
Le lundi 28 novembre 2011 ? 12:07 +0100, Ana a ?crit :> How can i replicate this in Linux: > source(file.choose()) > > > I've tried source(tkgetOpenFile()) but with no luckTry this instead (it works here): source(tclvalue(tkgetOpenFile())) Cheers
Ana wrote:
> How can i replicate this in Linux:
> source(file.choose())
>
Hi Ana,
There is probably some way to do this with a shell script, but I am
unaware of it. If you have the marvelous Tcl-Tk scripting language on
your Linux box, you could write something like this:
#!/usr/bin/wish
# sourceRfile a script to run an R command file
# SelectFile - A module for selecting a filename from a directory
# call "SelectFile mask" where 'mask' contains a mask or
filename
# default mask = *
proc GetFileList filemask {
set filelist [ glob -nocomplain $filemask ]
return $filelist
}
proc StringElement cmplist {
if { [ llength $cmplist ] > 1 } {
set cmpstring [ lindex $cmplist 0 ]
set cmpchar [ lindex $cmplist 1 ]
set stringlength [ string length $cmpstring ]
set charlength [ string length $cmpchar ]
set stringindex 0
while { $stringindex < $stringlength } {
set charindex 0
while { $charindex < $charlength } {
if { [ string index $cmpstring $stringindex ] ==\
[ string index $cmpchar $charindex ] } { return 1 }
incr charindex
}
incr stringindex
}
}
return 0
}
proc SelectFile mask {
global filename
global done
global rindex
if { [ string length $mask ] == 0 } {
set mask "*"
}
set path [ pwd ]
set done 0
set filename ""
set rindex 0
while { !$done } {
frame .sff -bd 3 -relief raised
label .sff.path -text $path
entry .sff.name
label .sff.filelabel -text "Directories"
frame .sff.fileframe
label .sff.dirlabel -text "Files"
frame .sff.dirframe
frame .sff.buttonframe
listbox .sff.fileframe.flist -selectmode single \
-yscroll ".sff.fileframe.yscroll set"
scrollbar .sff.fileframe.yscroll -relief sunken \
-command ".sff.fileframe.flist yview"
listbox .sff.dirframe.dlist -selectmode single \
-yscroll ".sff.dirframe.yscroll set"
scrollbar .sff.dirframe.yscroll -relief sunken \
-command ".sff.dirframe.dlist yview"
set filelist [ GetFileList $mask ]
lsort filelist
set fileindex 0
foreach filein $filelist {
if { [ file isfile $filein ] } {
.sff.fileframe.flist insert $fileindex $filein
incr fileindex
}
}
set dirlist [ GetFileList "*" ]
lsort dirlist
set dlist [ list ]
set dirindex 0
if { $path != "/" } {
.sff.dirframe.dlist insert $dirindex ".."
incr dirindex
}
foreach dirin $dirlist {
if { [ file isdirectory $dirin ] } {
.sff.dirframe.dlist insert $dirindex $dirin
incr dirindex
}
}
bind .sff.fileframe.flist <ButtonRelease-1> {
.sff.name delete 0 end
.sff.name insert 0 [ .sff.fileframe.flist get\
[ .sff.fileframe.flist curselection ] ]
}
button .sff.buttonframe.ok -text OK -command {
if { [ llength [ .sff.dirframe.dlist curselection ] ] } {
set filename [ .sff.dirframe.dlist get [ .sff.dirframe.dlist
curselection ] ]
} else {
if { [ llength [ .sff.fileframe.flist curselection ] ] } {
set filename [ .sff.fileframe.flist get [ .sff.fileframe.flist
curselection ] ]
} else {
if { [ llength [ .sff.name get ] ] } {
set filename [ .sff.name get ]
}
}
}
destroy .sff
}
button .sff.buttonframe.cancel -text Cancel -command {
set rindex -1
set done 1
set filename ""
destroy .sff
}
bind .sff.name <Return> {
set filename [ .sff.name get ]
destroy .sff
}
place .sff -relx 0.5 -rely 0.5 -anchor center -width 400\
-height 300
place .sff.path -relx 0.5 -rely 0.02 -anchor n
place .sff.name -relx 0.5 -rely 0.12 -anchor n
place .sff.filelabel -relx 0.05 -rely 0.22
place .sff.dirlabel -relx 0.55 -rely 0.22
place .sff.dirframe -relx 0.05 -rely 0.3 -relwidth 0.43\
-relheight 0.5
place .sff.fileframe -relx 0.55 -rely 0.3 -relwidth 0.43\
-relheight 0.5
place .sff.fileframe.flist -relx 0 -relwidth 0.85 -relheight 1
place .sff.fileframe.yscroll -relx 0.9 -rely 0.5\
-anchor center -relheight 1
place .sff.dirframe.dlist -relx 0 -relwidth 0.85 -relheight 1
place .sff.dirframe.yscroll -relx 0.9 -rely 0.5\
-anchor center -relheight 1
place .sff.buttonframe -relx 0.5 -rely 0.9 -anchor center
pack .sff.buttonframe.ok -side left
pack .sff.buttonframe.cancel -side right
.sff.name insert 0 $mask
focus .sff.name
tkwait window .sff
if { [ file isdirectory $filename ] } {
cd $filename
set path [ pwd ]
} elseif { [ StringElement [ list $filename "*?\[\]" ] ] } {
set mask $filename
} else {
set done 1
}
}
return $filename
}
wm geometry . 400x400
set Rfile [ SelectFile "*.R" ]
exec R CMD BATCH $Rfile
exit
Then simply create the following file named "helloR.R" in the same
directory:
sink("helloR.out")
cat("Hello, R\n")
sink()
chmod +x sourceRfile.tk
./sourceRfile.tk
Select the file "helloR.R" from the resulting menu, and that file will
be "sourced" by R. However, this is a bloody roundabout way to source
a
file in R.
Jim
> How can i replicate this in Linux: > source(file.choose()) > > > I've tried source(tkgetOpenFile()) but with no lucklibrary(gWidgetsRGtk2) options(guiToolkit="RGtk2") gfile(cont=T) Yvonnick Noel University of Brittany at Rennes Rennes, France