Re: [R] argv[0] --- again
I am amazed at the stuff Gabor knows. After I jokingly suggested R manuals were his bedtime reading he pretty much agreed: he reads documentation and code. He is in any case an extraordinary resource, and his contributions to this list are second to none. He has my vote of appreciation. more importantly, gabor also remembers what he reads. I usually read and then forget. gabor is great, but so are a number of other individuals here (brian ripley had to help me way too often, too). time for me to donate some more money to the R project again... regards, /iaw __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
hi gabor: thank you very much. how do you know this stuff? I just looked at the contributors() list, and you are not on it. may I highly suggest that a wrapper for this become part of the R base? it should also have a link from the commandArgs() help page to whatever this function should be called. regards, /iaw But you can still get it from the system. On XP Pro (maybe other Windows systems too?) place this in a.r out - system(wmic /output:stdout process, intern = TRUE) out - sapply(out, function(x) substr(x, 1, nchar(x)-1)) print(strsplit(grep(rcmd.exe.*batch, tolower(out), value = TRUE), *)[[1]][4]) and then at the command line type: Rcmd BATCH a.r and it will print out a.r __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
On 4/3/2006 8:18 AM, ivo welch wrote: hi gabor: thank you very much. how do you know this stuff? I just looked at the contributors() list, and you are not on it. may I highly suggest that a wrapper for this become part of the R base? it should also have a link from the commandArgs() help page to whatever this function should be called. The suggestion is really good, but I don't think it belongs in the base packages. It depends on too much: wmic on the path, only one BATCH job running at once. On the other hand, putting something like this on the R Wiki, or in a package of misc tools, or elsewhere online seems like a really good idea. Duncan Murdoch regards, /iaw But you can still get it from the system. On XP Pro (maybe other Windows systems too?) place this in a.r out - system(wmic /output:stdout process, intern = TRUE) out - sapply(out, function(x) substr(x, 1, nchar(x)-1)) print(strsplit(grep(rcmd.exe.*batch, tolower(out), value = TRUE), *)[[1]][4]) and then at the command line type: Rcmd BATCH a.r and it will print out a.r __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
hi gabor: is there a version of this for linux, too? regards, /iaw __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
I assume you could do the analogous processing using ps on UNIX. On 4/3/06, ivo welch [EMAIL PROTECTED] wrote: hi gabor: is there a version of this for linux, too? regards, /iaw __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
On 4/3/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: On 4/2/06, Duncan Murdoch [EMAIL PROTECTED] wrote: On 4/2/2006 9:34 PM, ivo welch wrote: dear R group: I have the probably fairly common problem that I would like to have one code.R file do different things if it is invoked from a symbolic link, which should be easy to uncover. $ ln -s code.R code-0.R $ ln -s code.R code-1.R $ R CMD BATCH code-1.R what needs to be in code-1.R to put code-1.r into a character vector? help appreciated. regards, /ivo welch PS :I read the past R-help posts on the subject, but apparently the older suggested solutions no longer work. (commandArgs() is not the answer, either.) And I did also not see it under the FAQ in the R programming section...and may I suggest this for the faq? I think the answer to this is platform dependent. In Windows, the answer is: you can't. The command line gets eaten by Rcmd.exe and isn't passed to R. But you can still get it from the system. On XP Pro (maybe other Windows systems too?) place this in a.r out - system(wmic /output:stdout process, intern = TRUE) out - sapply(out, function(x) substr(x, 1, nchar(x)-1)) print(strsplit(grep(rcmd.exe.*batch, tolower(out), value = TRUE), *)[[1]][4]) and then at the command line type: Rcmd BATCH a.r and it will print out a.r Here is one other approach. Create a batch file and have that batch call the R program using the program name as an argument, which the R program can then extract. The following uses the fact that lines beginning with rem are ignored by batch and the if statement happens to work in both R and batch. This allows us to combine the batch file and R program in the same file. This works at least on Windows XP. Place the following in a file called a.bat, say, and then at the Windows command line issue the command: a.bat a.bat will run as a batch file and then call itself as an R program passing its name to the R program in the argument list: rem - 3 if (rem == 3) 0 else goto:batch # R code goes here args - commandArgs() prog - sub(-, , grep(^-[^-], args, value = TRUE)) print(prog) q(no) :batch :: batch code goes here Rcmd BATCH -%0 %0 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
On Mon, 3 Apr 2006, ivo welch wrote: hi gabor: thank you very much. how do you know this stuff? I just looked at the contributors() list, and you are not on it. may I highly suggest that a wrapper for this become part of the R base? it should also have a link from the commandArgs() help page to whatever this function should be called. regards, /iaw I am amazed at the stuff Gabor knows. After I jokingly suggested R manuals were his bedtime reading he pretty much agreed: he reads documentation and code. He is in any case an extraordinary resource, and his contributions to this list are second to none. He has my vote of appreciation. David Scott _ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 AucklandNEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: [EMAIL PROTECTED] Graduate Officer, Department of Statistics ASC/NZSA 2006: Statistical Connections The joint conference of the Statistical Society of Australia Inc. and the New Zealand Statistical Association, July 3--6, 2006 in Auckland. Go to: http://www.statsnz2006.com/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
[ivo welch] how about people on [...] linux or unix [...] See ?commandArgs. -- François Pinard http://pinard.progiciels-bpi.ca __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
may I ask one more item? is there an official or best way to request that R add a standardized option that tells the user the R script name? I understand that most of the R developers read this group (bless them!), and the R developers may disagree about the usefulness/effort ratio of such a feature and not do it; I just want to suggest it, so that it ends up on the radar screen as a blip. regards, /iaw __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
On 4/3/2006 8:44 PM, ivo welch wrote: may I ask one more item? is there an official or best way to request that R add a standardized option that tells the user the R script name? I understand that most of the R developers read this group (bless them!), and the R developers may disagree about the usefulness/effort ratio of such a feature and not do it; I just want to suggest it, so that it ends up on the radar screen as a blip. The official and best ways are different. The official way is to submit a wishlist item as a bug report. This may or may not result in any action, depending on how easy it is, and whether anyone has any spare time. The best way is to write a patch that does what you want, and send it to a sympathetic member of R core who can commit it to the code base. In either case, it's a good idea to discuss the idea first on the r-devel list. Explain what R currently does, and what you want it to do instead, and why. Since it's a suggestion about R development, it won't receive the necessary attention on this list. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] argv[0] --- again
dear R group: I have the probably fairly common problem that I would like to have one code.R file do different things if it is invoked from a symbolic link, which should be easy to uncover. $ ln -s code.R code-0.R $ ln -s code.R code-1.R $ R CMD BATCH code-1.R what needs to be in code-1.R to put code-1.r into a character vector? help appreciated. regards, /ivo welch PS :I read the past R-help posts on the subject, but apparently the older suggested solutions no longer work. (commandArgs() is not the answer, either.) And I did also not see it under the FAQ in the R programming section...and may I suggest this for the faq? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
On 4/2/2006 9:34 PM, ivo welch wrote: dear R group: I have the probably fairly common problem that I would like to have one code.R file do different things if it is invoked from a symbolic link, which should be easy to uncover. $ ln -s code.R code-0.R $ ln -s code.R code-1.R $ R CMD BATCH code-1.R what needs to be in code-1.R to put code-1.r into a character vector? help appreciated. regards, /ivo welch PS :I read the past R-help posts on the subject, but apparently the older suggested solutions no longer work. (commandArgs() is not the answer, either.) And I did also not see it under the FAQ in the R programming section...and may I suggest this for the faq? I think the answer to this is platform dependent. In Windows, the answer is: you can't. The command line gets eaten by Rcmd.exe and isn't passed to R. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
thank you, duncan. yikes. how about people on sane (sorry, mean linux or unix) systems... ;-). regards, /iaw On 4/2/06, Duncan Murdoch [EMAIL PROTECTED] wrote: On 4/2/2006 9:34 PM, ivo welch wrote: dear R group: I have the probably fairly common problem that I would like to have one code.R file do different things if it is invoked from a symbolic link, which should be easy to uncover. $ ln -s code.R code-0.R $ ln -s code.R code-1.R $ R CMD BATCH code-1.R what needs to be in code-1.R to put code-1.r into a character vector? help appreciated. regards, /ivo welch PS :I read the past R-help posts on the subject, but apparently the older suggested solutions no longer work. (commandArgs() is not the answer, either.) And I did also not see it under the FAQ in the R programming section...and may I suggest this for the faq? I think the answer to this is platform dependent. In Windows, the answer is: you can't. The command line gets eaten by Rcmd.exe and isn't passed to R. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] argv[0] --- again
On 4/2/06, Duncan Murdoch [EMAIL PROTECTED] wrote: On 4/2/2006 9:34 PM, ivo welch wrote: dear R group: I have the probably fairly common problem that I would like to have one code.R file do different things if it is invoked from a symbolic link, which should be easy to uncover. $ ln -s code.R code-0.R $ ln -s code.R code-1.R $ R CMD BATCH code-1.R what needs to be in code-1.R to put code-1.r into a character vector? help appreciated. regards, /ivo welch PS :I read the past R-help posts on the subject, but apparently the older suggested solutions no longer work. (commandArgs() is not the answer, either.) And I did also not see it under the FAQ in the R programming section...and may I suggest this for the faq? I think the answer to this is platform dependent. In Windows, the answer is: you can't. The command line gets eaten by Rcmd.exe and isn't passed to R. But you can still get it from the system. On XP Pro (maybe other Windows systems too?) place this in a.r out - system(wmic /output:stdout process, intern = TRUE) out - sapply(out, function(x) substr(x, 1, nchar(x)-1)) print(strsplit(grep(rcmd.exe.*batch, tolower(out), value = TRUE), *)[[1]][4]) and then at the command line type: Rcmd BATCH a.r and it will print out a.r __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html