similar to: Why this statement does not print anything in an if-statement that includes 'q()'?

Displaying 20 results from an estimated 10000 matches similar to: "Why this statement does not print anything in an if-statement that includes 'q()'?"

2009 Aug 28
1
How to convert a string passed as an argument to a vector?
Hi, $ cat commandArgs.R args=commandArgs(trailingOnly=TRUE) args[1]+10 I have the above code. But the following command line gives me an error. I am wondering what is the correct way to convert a string to a vector? $ Rscript commandArgs.R 1:3 > args=commandArgs(trailingOnly=TRUE) > args[1]+10 Error in args[1] + 10 : non-numeric argument to binary operator Execution halted Regards, Peng
2009 Aug 20
1
Command line option to an R script running through Rscript
Hi, I know that I can use the following script to get the command line options for an R script. But the output shows two many irrelevant arguments. For example, I only want to pass "a", "b" and "c" to the script. The first 5 elements in the variable 'args' are not what I want. I am wondering what is the correct way to pass command line options to an R script.
2009 Sep 22
1
How to get the current script file name in the script?
Hi, Right now, I hardcode the file name in the script. But when I change the script name, I have to change the file name in the script to make sure the file name inside the script is synchronized with the script name. I am wondering if there is an automatic way to get the script file name in a script. Regards, Peng $ Rscript get_file_name.R > print('get_file_name.R') [1]
2009 Nov 19
4
Is there an variant of apply() that does not return anything?
There are a few version of apply() (e.g., lapply(), sapply()). I'm wondering if there is one that does not return anything but just silently apply a function to the list argument. For example, the plot function is applied to each element in 'alist'. It is redundant to return anything from apply. apply(alist,function(x){ plot each element of alist})
2009 Sep 06
2
How to pop up the graphics window from Rscript?
Hi, I am wondering how to pop up the graphics window from Rscript. I run the following code, but I don't see the graphics window, even transiently. Regards, Peng $ Rscript plot.R > x=1:10 > y=1:10 > plot(x,y) >
2010 Jan 01
5
How to not to terminate read.table if the input file is empty?
read.table terminates the program if the input file is empty. Is there way to let the program continue and return me a NULL instead of terminating the program? $ Rscript read_empty.R > read.table("empty_data.txt") Error in read.table("empty_data.txt") : no lines available in input Execution halted $ cat read_empty.R read.table("empty_data.txt") $ cat
2009 Dec 18
4
How to print to file?
I don't find a function to print a string to file. Would somebody let me know what function I should use?
2011 Mar 14
1
Rscript, hashbang, and arguments
Hi, I have a bunch of R scripts which have the hash bang !/usr/bin/env Rscript and I typically run these scripts by passing in some parameters like this: ./nameOfRScript arg1 arg2 ... I know Rscript has the option to run in --vanilla. Where exactly do I insert the --vanilla option? When I do something like this: ./nameOfRScript --vanilla arg1 arg2 ... And I try to access the commandArgs,
2008 Jan 05
1
Rscript argument processing minor bug with -g
I think there's a minor bug in the argument-processing carried out by Rscript. The effect is that if one passes "-g" as a flag to the script, it is erroneously exposed to the main executable's argument processing and therefore generates a message about not being able to comply with the request for a particular GUI. Uppercase G is fine as are the other 25 letters in upper or
2012 Mar 28
2
getopt does not work as expected!
I have the following script (also attached): #!/usr/bin/Rscript spec=matrix(c( 'verbose', 'v', 1, "integer", 'help' , 'h', 0, "logical" ),ncol=4, byrow=TRUE) spec.dim=dim(spec) spec.opt.long=spec[,1] spec.opt.short=spec[,2] spec.opt.l <- spec.dim[1] infile <- "test.dat" args=commandArgs(TRUE); l=length(args) self =
2009 Sep 06
2
How to wait for a user response in Rscript?
Hi, In 'example(barplot)' running in R, I see 'Hit <Return> to see next plot:', then R waits for my input. I am wondering how to wait for a user response in Rscript. Regards, Peng
2012 May 03
1
is there a way of identifying batch mode running?
Hello list Is there a way of identifying from within R whether a script has been source(d) from Rgui.exe or via Rscript.exe in batch mode? For the code I have I use the commandArgs() function to pick up command line args when running in batch mode via Rscript.exe However I like to get the code working manually first using source("MyRCode.r") I'd like to be able to put something at
2007 Apr 01
2
commandArgs usage and --args invokation
Dear R experts: I am a bit stymied by how the argument picking-off works in R batch file usage. $ cat commandArgs.R cat(" Command Line Arguments were ", commandArgs(), "\n"); $ /usr/bin/R CMD BATCH commandArgs.R --args 1 2 3 $ /usr/bin/R --args 1 CMD BATCH commandArgs.R ... I am now getting into interactive mode ?! I guess it really is skipping the rest of the command line
2009 Sep 16
1
How to convert a frame to a matrix while maintaining that a number is still a number?
Hi, See the code below. 'x' is a frame. x$C1 are all numbers 1, 2 and 3. 'as.matrix(x)' convert x$C1 to strings "1", "2" and "3". I'm wondering how to maintain that the first column of 'as.matrix(x)' still numbers. Regards, Peng $ cat read.csv "C1","C2" "1","x" "2","y"
2011 Apr 22
3
Parametrized object name in Save statement
Greetings All, I am looking to write a parametrized Rscript that will accept a variable name(that also is the name of the flat file), transform the data into a data frame and preform various modeling on the structure and save the output and plot of the model. In this example i am using a rpart decision tree. The only problem i am having is integrating the parameter into the internal object name
2009 Oct 27
2
Why I get this error? Error in close.connection(f) : invalid connection
I don't understand why I can not close 'f'. This may be very simple, but I don't see why. Could somebody let me know? $ cat gzfile.csv "","V1","V2","V3","V4","V5" "1",1,5,9,13,17 "2",2,6,10,14,18 "3",3,7,11,15,19 "4",4,8,12,16,20 $ Rscript gzfile.R > f =
2009 Aug 10
5
Example scripts for R Manual
Hi, I am wondering if some experienced users would help put the ready-to-run code of the examples in the manuals. It would help new users learn R faster by putting all the examples in an ready-to-run R script file. Can somebody help do so sometime and post the code along with the pdf manuals? http://cran.r-project.org/manuals.html Regards, Peng
2012 Oct 29
6
export variable from bash to R
Dear R experts This probably seems very easy to you guys, but I'm a beginner and would be really glad if someone helped me with this: I am trying to automate the execution of an R script (let's call it "myscript.R") by passing a variable from a bash script to myscript.R. I know I can use the command Rscript, but I don't know how to declare in bash which variable will be
2010 Feb 03
5
How to export the examples in help(something) to a file?
Some examples in the help page are too long to be copied from screen. Could somebody let me know some easy way on how to extract the example to a file so that I can play with them?
2006 Apr 04
1
request to add argv[0]
Dear R Developers: This has come up repeatedly in the r-help mailing list, most recently in a thread started by myself. The answers have been changing over the years. Would it be possible and easy for R to offer a global read-only option that gives the name of the currently executing R script, i.e., the equivalent of argv[0] in C? (PS: An even better mechanism would be the ability to pick