An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100114/0768678a/attachment.ksh>
Giving parameters from shell
4 messages · cihan inan, Paul Hiemstra, Don MacQueen
cihan inan wrote:
Hi I want to give parameters for my function from the shell. I mean
I defined a function like these:
work1.R :
myfunc <- function(x,y) {
z = x + y
z
}
and now I want to use shell to give parameters like " ./work1.R (3,5) " to
get sum 8.
so what should I do?
[[alternative HTML version deleted]]
______________________________________________ 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.
Hi, Add the following shebang line at the top of your script: #! /path/to/Rscript The following lines will get you the parameters passed on by the user: args = commandArgs(TRUE) cheers, Paul
Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100114/50176708/attachment.pl>
Try for yourself and see. (it's not difficult to try) For example, put the line in both places, followed by print(args) and see what happens. -Don
At 11:49 PM +0200 1/14/10, cihan inan wrote:
Content-Type: text/plain Content-Disposition: inline Content-length: 1496 I want to learn one more thing. You said args = commandArgs(TRUE) should I write this sentence in my function or out of my function area ? can you give me an example .r file ? 2010/1/14 Paul Hiemstra <p.hiemstra at geo.uu.nl>
cihan inan wrote:
Hi I want to give parameters for my function from the shell. I mean
I defined a function like these:
work1.R :
myfunc <- function(x,y) {
z = x + y
z
}
and now I want to use shell to give parameters like " ./work1.R (3,5) " to
get sum 8.
so what should I do?
[[alternative HTML version deleted]]
______________________________________________ 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.
Hi, Add the following shebang line at the top of your script: #! /path/to/Rscript The following lines will get you the parameters passed on by the user: args = commandArgs(TRUE) cheers, Paul -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://*intamap.geo.uu.nl/~paul
-- ?zg?rl?k i?in...http://*www.*pardus.org.tr/ [[alternative HTML version deleted]]
______________________________________________ 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.
-------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062