%cat stock.R #! /usr/local/bin/Rscript args <- commandArgs(TRUE) args x <- read.csv("000301.csv") matplot(x[,1],x[,-1],type="l") #q(save="no") %Rscript stock.R 000301.csv [1] "000301.csv" matplot doesnot draw anything(no drawing window). Howeve, in R, source works great!>source("stock.R")Sincerely! -- View this message in context: http://n4.nabble.com/Why-doesnot-Rscript-work-tp963418p963418.html Sent from the R help mailing list archive at Nabble.com.
Hi, Rscript is meant for non-interactive use, so the default device is not the same as when you run R. If you really want a window, open it yourself by calling the appropriate function (X11, windows, ... ) or reset the "device" option to whichever device you want to use, but it will disappear at the end of the script, so not very interesting. You probably should open a png device or something and then write the grap there. See ?png, ?pdf, ?X11, ?options, ?Rscript Romain On 12/14/2009 10:59 AM, z_axis wrote:> %cat stock.R > #! /usr/local/bin/Rscript > > args<- commandArgs(TRUE) > args > > x<- read.csv("000301.csv") > matplot(x[,1],x[,-1],type="l") > #q(save="no") > > %Rscript stock.R 000301.csv > [1] "000301.csv" > matplot doesnot draw anything(no drawing window). > > Howeve, in R, source works great! >> source("stock.R") > > Sincerely! >-- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/HlX9 : new package : bibtex |- http://tr.im/Gq7i : ohloh `- http://tr.im/FtUu : new package : highlight
On Mon, 14 Dec 2009, z_axis wrote:> > %cat stock.R > #! /usr/local/bin/Rscript > > args <- commandArgs(TRUE) > args > > x <- read.csv("000301.csv") > matplot(x[,1],x[,-1],type="l") > #q(save="no") > > %Rscript stock.R 000301.csv > [1] "000301.csv" > matplot doesnot draw anything(no drawing window).Incorrect: it plots on the default device for batch use, most likely pdf(), so look for a file Rplots.pdf. You have ignored the posting guide so we do not know your OS. On a Unix-alike, you could explicitly open X11() (quartz() on a Mac), but it would be closed again at the end of your script unless you arrange to pause the script.> Howeve, in R, source works great! >> source("stock.R") > > Sincerely!Real names and the courtesy of a signature block are preferred here. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595