hello Is it possible to execute Unix command from R prompt? for example ls cd .. In matlab this possible by adding "!" !ls !cd .. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
unix
16 messages · Meriema Belaidouni, Anders Nielsen, Peter Dalgaard +8 more
Try something like:
R>system("ls")
Anders
On Mon, 6 Nov 2000, Meriema Belaidouni wrote:
hello Is it possible to execute Unix command from R prompt? for example ls cd .. In matlab this possible by adding "!" !ls !cd ..
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Meriema Belaidouni <meriema at info.univ-angers.fr> writes:
ls cd .. In matlab this possible by adding "!" !ls !cd ..
Use system("ls"). We've had the "!" convention at some point, but as I
remember it, people got tired of having it kick in unexpectedly where
logical "not" was intended, and we decided that it was probably a bad
idea to have a syntactically correct R expression do something
completely different when it happened to sit at the beginning of a line...
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Meriema Belaidouni <meriema at info.univ-angers.fr> writes:
hello Is it possible to execute Unix command from R prompt? for example ls cd ..
system("ls")
[...]
Cheers
Ross Darnell
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Yes, you can use this:
system("date > date.txt")
for example
Meriema Belaidouni wrote:
hello Is it possible to execute Unix command from R prompt? for example ls cd .. In matlab this possible by adding "!" !ls !cd .. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Olivier Houix <houix at ircam.fr> tel: 01 44 78 15 51 Equipe Perception et Cognition Musicales http://www.ircam.fr/ IRCAM 1 place Igor Stravinsky 75004 Paris -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I'd like to point out a potential confusion. Although the advice about system() is technically correct, for the particular case of changing directories you probably want to use getwd/setwd [I think system() spawns its own shell, so changing directories with system() isn't persistent]. For example:
getwd() ## start in my home directory
[1] "/home/ben"
system("cd ..") ## this executes OK but ...
getwd()
[1] "/home/ben" ## I'm still in the same working directory
setwd("..") ## this is the way to change working directory
NULL
getwd() ## now I've moved up one
[1] "/home"
system("pwd") would do the same thing as getwd(), but is specific to Unix
(whereas getwd() should also work on Windows etc.)
For my two cents, the "shorthand" command that I'd like to have in R
would be a shortcut for referring to .Last.value like %, %% in Maple ...
might be hard to find a special character that's not already used for
something, though.
On 6 Nov 2000, Peter Dalgaard BSA wrote:
Meriema Belaidouni <meriema at info.univ-angers.fr> writes:
ls cd .. In matlab this possible by adding "!" !ls !cd ..
Use system("ls"). We've had the "!" convention at some point, but as I
remember it, people got tired of having it kick in unexpectedly where
logical "not" was intended, and we decided that it was probably a bad
idea to have a syntactically correct R expression do something
completely different when it happened to sit at the beginning of a line...
318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 6 Nov 2000, Houix Olivier wrote:
Yes, you can use this:
system("date > date.txt")
Meriema Belaidouni wrote:
hello Is it possible to execute Unix command from R prompt? for example ls cd ..
Both yes and no - I don't think you can change the working directory, because system() runs a shell process to termination:
system("pwd")
/home/rsb
system("cd tmp")
system("pwd")
/home/rsb
system("cd tmp; pwd")
/home/rsb/tmp
system("pwd")
/home/rsb Is there a way to do this too? Roger
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: Roger.Bivand at nhh.no and: Department of Geography and Regional Development, University of Gdansk, al. Mar. J. Pilsudskiego 46, PL-81 378 Gdynia, Poland. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 6 Nov 2000 17:17:14 +0100 (CET), Roger Bivand (RB) wrote:
RB> Both yes and no - I don't think you can change the working directory, RB> because system() runs a shell process to termination:
system("pwd")
RB> /home/rsb
system("cd tmp")
system("pwd")
RB> /home/rsb
system("cd tmp; pwd")
RB> /home/rsb/tmp
system("pwd")
RB> /home/rsb RB> Is there a way to do this too? Sure, using setwd():
system("pwd")
/home/Leisch/bin
setwd("/tmp")
NULL
system("pwd")
/tmp best, .f -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 6 Nov 2000 ben at zoo.ufl.edu wrote:
For my two cents, the "shorthand" command that I'd like to have in R would be a shortcut for referring to .Last.value like %, %% in Maple ... might be hard to find a special character that's not already used for something, though.
I agree with this suggestion, I was going to suggest it myself at one point. (I think it is Mathematica that uses %, %% and Maple uses ", "",...) Bill -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
... and Matlab uses "ans" and Mathematica effectively uses %, %% Would be nice to have something simpler than .Last.value YG ----- Original Message ----- From: "Bill Simpson" <wsi at gcal.ac.uk> To: <r-help at stat.math.ethz.ch> Sent: Tuesday, November 07, 2000 4:11 AM Subject: Re: [R] unix
On Mon, 6 Nov 2000 ben at zoo.ufl.edu wrote:
For my two cents, the "shorthand" command that I'd like to have in R would be a shortcut for referring to .Last.value like %, %% in Maple ... might be hard to find a special character that's not already used for something, though.
I agree with this suggestion, I was going to suggest it myself at one point. (I think it is Mathematica that uses %, %% and Maple uses ", "",...) Bill -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Yves Gauvreau <cyg at sympatico.ca> writes:
... and Matlab uses "ans" and Mathematica effectively uses %, %% Would be nice to have something simpler than .Last.value
Perhaps I am stating the obvious or being extremely stupid but you can
create a function:
lv <- function()
{
.Last.value
}
And then use lv() whenever you need .Last.value.
Mark
--
Mark Myatt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Good suggestion and simple enough. I had in mind something more like "version" which doesn't require the "()", but your idea is excellent. Regards YG ----- Original Message ----- From: "Mark Myatt" <mark at myatt.demon.co.uk> To: "Yves Gauvreau" <cyg at sympatico.ca> Cc: "Bill Simpson" <wsi at gcal.ac.uk>; <r-help at stat.math.ethz.ch> Sent: Tuesday, November 07, 2000 8:43 AM Subject: [R] .Last.value or % or ANS or ... (was unix)
Yves Gauvreau <cyg at sympatico.ca> writes:
... and Matlab uses "ans" and Mathematica effectively uses %, %% Would be nice to have something simpler than .Last.value
Perhaps I am stating the obvious or being extremely stupid but you can
create a function:
lv <- function()
{
.Last.value
}
And then use lv() whenever you need .Last.value.
Mark
--
Mark Myatt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 7 Nov 2000, Mark Myatt wrote:
Yves Gauvreau <cyg at sympatico.ca> writes:
... and Matlab uses "ans" and Mathematica effectively uses %, %% Would be nice to have something simpler than .Last.value
Perhaps I am stating the obvious or being extremely stupid but you can
create a function:
lv <- function()
{
.Last.value
}
And then use lv() whenever you need .Last.value.
How do you say "give me the output I saw three steps ago?" In Mathematica you would use %%% or Out[-3]. Bill -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Bill Simpson <wsi at gcal.ac.uk> writes:
On Tue, 7 Nov 2000, Mark Myatt wrote:
Yves Gauvreau <cyg at sympatico.ca> writes:
... and Matlab uses "ans" and Mathematica effectively uses %, %% Would be nice to have something simpler than .Last.value
Perhaps I am stating the obvious or being extremely stupid but you can
create a function:
lv <- function()
{
.Last.value
}
And then use lv() whenever you need .Last.value.
How do you say "give me the output I saw three steps ago?" In Mathematica you would use %%% or Out[-3].
Why not implement a LIFO stack? Here is a first attempt:
#
# Flush the stack
# (call this to create the stack)
#
flush <- function()
{
stack <<- list()
}
#
# Push a value onto the stack
#
push <- function()
{
stack <<- c(stack, .Last.value)
}
#
# Pull a value from the stack
# (default is last pushed value)
#
pull <- function(x = 0)
{
stack[[length(stack) - x]]
}
#
# Pull a value from the stack and remove it
# (default is last pushed value)
#
pop <- function(x = 0)
{
pop <- stack[[length(stack) - x]]
stack <<- stack[-length(stack) + x]
pop
}
You still need to push() the values you want to keep onto the stack.
Another limitations of the above code is that objects are stored as
'atoms':
> flush()
> a <- c(1,2,3,4,5)
> mean(a)
[1] 3
> push()
> stack
[[1]]
[1] 3
> a
[1] 1 2 3 4 5
> push()
> stack
[[1]]
[1] 3
[[2]]
[1] 1
[[3]]
[1] 2
[[4]]
[1] 3
[[5]]
[1] 4
[[6]]
[1] 5
> pull(1)
[1] 4
> pop(1)
[1] 4
> stack
[[1]]
[1] 3
[[2]]
[1] 1
[[3]]
[1] 2
[[4]]
[1] 3
[[5]]
[1] 5
Which makes it pretty useless for vector and matrix results but there
should be a way round that.
Mark
--
Mark Myatt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
[stack implementation] But if I could remember to push() every time I could remember to assign everything to temporary variables anyway ...
318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ben at zoo.ufl.edu writes:
[stack implementation] But if I could remember to push() every time I could remember to assign everything to temporary variables anyway ...
I suppose so. It might be possible to do an automatic push() on any assignment but that would create an enormous stack just retrieving a dataset or fitting a model. Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._