Hi,
My thanks to Bill Dunlap, Paul Gross, David Pedack, William Osburn for their
replies to my query. The environmental variables route suits my application
best and I simply have a line in a dos batch file
splus.exe splusvar1=1, splusvar2="hello", splusvar3=456 /BATCH script.ssc"
output.txt error.txt
and then the script file picks up the values using getenv("splusvar1") etc.
Many thanks,
Glenn
I have attached a longer mail from Paul giving further details.
####################################
Use environment variables.
Retrieve their values in Splus with getenv("varName") or
Sys.getenv("varName).
Set them either in a shell-specific way (set varName="my file.txt"
in a DOS window, varName="my file.txt";export varName or
varName="my file.txt" Splus in sh, etc.)
or on the Splus command line
Splus START varName="my file.txt" ...
in any shell.
----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
#####################################
Why not just create a single wrapper script for all the scripts you want
to run. You could import an excel/csv file with any parameters you
might want and then just pass them one set at a time to your
scripts/functions. Then when you are ready to run all your scripts just
edit the excel/csv file and kick off the batch for your single 'master'
wrapper script.
Hope this helps,
David Pedack
#######################################
Are you talking about daughter scripts?
look at source()
William Osburn
Glenn,
#######################################
In short if your script contains the following:
a = getenv("a")
cat(" a : ", a, "\n")
then from the shell:
> Splus START a=1234 < ~/splus/args.s
S-PLUS : Copyright (c) 1988, 2007 Insightful Corp.
S : Copyright Insightful Corp.
Version 8.0.4 for Linux 2.4.21, 32-bit : 2007
Working data will be in /u1/pgross/MySwork
Warning messages:
Cannot open audit file ("/u1/pgross/MySwork/.Data/.Audit") in:
setAudit()
a : 1234
Please see the following mail thread with Insightful as well for further
options.
Paul Gross
Hi Paul,
Thank you for your comments and also for your additional example of
using Splus START to pass in arguments.
I apologize; I was a little unclear in my earlier email. The
commandArgs() function does return a value, however, it does not work in
the way that you (and other users) were expecting it to work. The bug
report I mentioned in my previous email was to allow commandArgs() to
work in the way that you illustrated in your email (this would also make
it compatible to the way R's
commandArgs() function works).
Along these same lines I am also filing an enhancement request to add
examples to the commandArgs() function help file so that it is clearer
how the commandArgs() function is meant to be used. Currently, if I run
commandArgs() at my S-PLUS 8.0.4 for unix command prompt, I get the path
to the sqpe file that is being executed to run the S-PLUS program.
However, the portion in the help file on returning the arguments on the
command line is very vague and confusing as to what the actual output
would be. Hopefully adding some examples and perhaps a longer
discussion on the function will help clarify how to use the
commandArgs() function.
Thank you again for your comments! Please let me know if you have any
other questions.
Sincerely,
Rachel
========================================================================
=
Rachel Flodin email: support@insightful.com
Technical Support Engineer FAX: (206) 283-8691
Insightful Corporation Phone: (206) 283-8802 ext.235
www.insightful.com 1-800-569-0123 ext.235
========================================================================
=
In order to improve our service we would appreciate hearing from you.
Please take a few minutes to complete this short survey.
http://www.zoomerang.com/survey.zgi?p=WEB226JE6MVRGV
>---------------- Original Message ----------------
> From: Paul Gross
> Sent: 2/5/2008
> To: support
> CC: %4
> Subject: RE: Incident #98154: commandArgs in S-plus
> >Hello Rachel,
>
>Thank you for your help. I have two comments:
>
>1. It would be helpful if Insightful would remove the man page for
>commandArgs given that this functionality does not exist. Apparently
>the man page for this non-existent command has existed in many, if not
>all, releases of S-plus.
>
>2. The following idiom can also be used:
>
>Splus START x=foo y=bar
>Then:
> > getenv("x")
> x
> "foo"
> > getenv("y")
> y
> "bar"
>
>This also works in batch mode.
>
>Thanks again,
>
>Paul
>
>
>
>
>
>-----Original Message-----
>From: support@insightful.com [mailto:support@insightful.com]
>Sent: Monday, February 04, 2008 3:20 PM
>To: Gross, Paul
>Subject: Incident #98154: commandArgs in S-plus
>
>Hello Paul,
>
>Thank you for your question regarding commandArgs().
>
>Unfortunately, as you have found commandArgs() does not work. There is
>a bug report filed to report this behavior. I have added your name and
>comments from your email to the bug report.
>
>There are two options that you can use as a workaround, both involving
>SBATCH:
>
>1. Create an environment variable to hold the parameter values:
>
>For example, in the bash shell:
>
>export MYDATA="parameters"
>
>or in csh shell:
>
>setenv MYDATA="parameters"
>
>Then, you can call getenv() inside of the script file you are calling.
>For example, if I had a file named infile.q, I would add the line:
>
>args <- getenv("MYDATA")
>
>to extract the environment variable value. Then, I would run the
>following at command line:
>
>> Splus SBATCH infile.q outfile.q
>
>to read in and run the infile.q file.
>
>2. Create a file of the parameters and read it in the infile.q
>
>For example, create file:
>
>> echo parameters > test.in
>
>Then, inside of infile.q call:
>
>x <- scan("test.in", what=<specify param_type>)
>
>Finally, we would run the following at the command prompt:
>
>Splus SBATCH infile.q outfile.q
>
>You can read more about SBATCH by typing the following at your S-PLUS
>command
>prompt:
>
>> ?SBATCH
>
>I hope this information is helpful! Please let me know if you have any
>questions.
>
>Sincerely,
>
>Rachel Flodin
>
>=======================================================================
>=
>=
> Rachel Flodin email:
support@insightful.com
> Technical Support Engineer FAX: (206) 283-8691
> Insightful Corporation Phone: (206) 283-8802 ext.235
> www.insightful.com 1-800-569-0123
ext.235
>
>=======================================================================
>=
>=
>
>In order to improve our service we would appreciate hearing from you.
>Please take a few minutes to complete this short survey.
>http://www.zoomerang.com/survey.zgi?p=WEB226JE6MVRGV
>
>
>>---------------- Original Message ----------------
>> From: Paul Gross
>> Sent: 1/30/2008
>> To: support
>> CC: %4
>> Subject: commandArgs in S-plus
>
>> >This is with regard to:
>>devyxsv010{pgross}=> /usr/local/splus8.0.4/cmd/Splus -e VERSION S-PLUS
>>Version 8.0.4 for Linux 2.4.21, 32-bit : 2007 Master ID created Wed
>>May
>
>>2 11:09:02 PDT 2007 Based on S Version 4, Wed June 2, 07:41:00 EDT
>>1999
>>
>>
>>I run the following at the command line:
>>
>>Splus < myScript ARG
>>
>>where myScript consists of the following:
>>
>>for (arg in commandArgs()){ cat(arg, "\n") }
>>
>>In any version of Splus, this leads to an error, e.g.:
>>
>>=> /usr/local/splus8.0.4/cmd/Splus < myScript ARG
>>/usr/local/splus8.0.4/cmd/Splus: line 290: exec: ARG: not found
>>
>>Does this not work in S-plus? The documenation says:
>>
>>TITLE:
>> Function commandArgs
>>
>>USAGE:
>> commandArgs()
>>
>>ARGUMENTS:
>>
>>DESCRIPTION:
>>
>>
>> returns the command-line invoking this S session, as a
>character
>> vector.The first element is the name by which the S executable
>>was
>> invoked; the remainingelements, if any, are the arguments on
>the
>> command line.
>>
>>What am I missing?
>>
>>Thanks,
>>Paul
>>
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Glenn Treacy
Sent: Thursday, June 12, 2008 2:12 PM
To: s-news@wubios.wustl.edu
Subject: [S] Passing arguments to a script file called in batch mode
Hi,
Does anyone know whether it is possible to pass arguments to a script
file that is called in batch mode? I am looking for a way of creating a
dynamic script file that can calls different code depending on the the
value of a variable in a batch file. I have a whole series of script
files that are very similar and this was one idea of consolidating them
into one.
Anyone got an idea?
Thanks in advnace,
Glenn
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
THE INFORMATION CONTAINED IN THIS MESSAGE AND ANY ATTACHMENT MAY BE PRIVILEGED,
CONFIDENTIAL, PROPRIETARY OR OTHERWISE PROTECTED FROM DISCLOSURE. If the reader
of this message is not the intended recipient, you are hereby notified that any
dissemination, distribution, copying or use of this message and any attachment
is strictly prohibited. If you have received this message in error, please
notify us immediately by replying to the message and permanently delete it from
your computer and destroy any printout thereof.
**********************************************************************************
Irish Life Investment Managers Limited is authorised by the Financial
Regulator. Irish Life Investment Managers Limited Registered Office: Beresford
Court, Beresford Place, Dublin 1. Registered in Ireland Number 116000
While Irish Life Investment Managers uses reasonable efforts to ensure that the
information contained in this email is current, accurate and complete at the
date of publication, no representations or warranties are made (express or
implied) as to the reliability, accuracy or completeness of such information.
Irish Life Investment Managers therefore cannot be held liable for any loss
arising directly or indirectly from the use of, or any action taken in reliance
on, any information contained in this email.
This material is for information only and does not constitute an offer or
recommendation to buy or sell any investment, or subscribe to any investment
management or advisory service. It is intended for the use of institutional and
other professional investors. Past performance is not indicative of future
results. The value of funds we manage may fall as well as rise.
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. If
you have received this email in error please notify the system manager. This
footnote also confirms that this email message has been swept for the presence
of computer viruses.
**********************************************************************************
--- Begin Message ---
|
To: |
"Treacy, Glenn" <glenn.treacy@ilim.com> |
|
Subject: |
RE: [S] Passing arguments to a script file called in batch mode (fwd) |
|
From: |
"Glenn Treacy" <gatreacy@maths.tcd.ie> |
|
Date: |
Tue, 17 Jun 2008 17:48:48 +0100 |
|
Thread-index: |
AcjQmgd+Ku7WkA78QWG7lfgc1BPNOQ== |
|
Thread-topic: |
[S] Passing arguments to a script file called in batch mode (fwd) |
---------- Forwarded message ----------
Date: Fri, 13 Jun 2008 13:13:28 -0400
From: "Gross, Paul" <paul.gross@blackrock.com>
To: Glenn Treacy <gatreacy@maths.tcd.ie>
Subject: RE: [S] Passing arguments to a script file called in batch mode
Glenn,
In short if your script contains the following:
a = getenv("a")
cat(" a : ", a, "\n")
then from the shell:
> Splus START a=1234 < ~/splus/args.s
S-PLUS : Copyright (c) 1988, 2007 Insightful Corp.
S : Copyright Insightful Corp.
Version 8.0.4 for Linux 2.4.21, 32-bit : 2007
Working data will be in /u1/pgross/MySwork
Warning messages:
Cannot open audit file ("/u1/pgross/MySwork/.Data/.Audit") in:
setAudit()
a : 1234
Please see the following mail thread with Insightful as well for further
options.
Paul Gross
Hi Paul,
Thank you for your comments and also for your additional example of
using Splus START to pass in arguments.
I apologize; I was a little unclear in my earlier email. The
commandArgs() function does return a value, however, it does not work in
the way that you (and other users) were expecting it to work. The bug
report I mentioned in my previous email was to allow commandArgs() to
work in the way that you illustrated in your email (this would also make
it compatible to the way R's
commandArgs() function works).
Along these same lines I am also filing an enhancement request to add
examples to the commandArgs() function help file so that it is clearer
how the commandArgs() function is meant to be used. Currently, if I run
commandArgs() at my S-PLUS 8.0.4 for unix command prompt, I get the path
to the sqpe file that is being executed to run the S-PLUS program.
However, the portion in the help file on returning the arguments on the
command line is very vague and confusing as to what the actual output
would be. Hopefully adding some examples and perhaps a longer
discussion on the function will help clarify how to use the
commandArgs() function.
Thank you again for your comments! Please let me know if you have any
other questions.
Sincerely,
Rachel
========================================================================
=
Rachel Flodin email: support@insightful.com
Technical Support Engineer FAX: (206) 283-8691
Insightful Corporation Phone: (206) 283-8802 ext.235
www.insightful.com 1-800-569-0123 ext.235
========================================================================
=
In order to improve our service we would appreciate hearing from you.
Please take a few minutes to complete this short survey.
http://www.zoomerang.com/survey.zgi?p=WEB226JE6MVRGV
>---------------- Original Message ----------------
> From: Paul Gross
> Sent: 2/5/2008
> To: support
> CC: %4
> Subject: RE: Incident #98154: commandArgs in S-plus
> >Hello Rachel,
>
>Thank you for your help. I have two comments:
>
>1. It would be helpful if Insightful would remove the man page for
>commandArgs given that this functionality does not exist. Apparently
>the man page for this non-existent command has existed in many, if not
>all, releases of S-plus.
>
>2. The following idiom can also be used:
>
>Splus START x=foo y=bar
>Then:
> > getenv("x")
> x
> "foo"
> > getenv("y")
> y
> "bar"
>
>This also works in batch mode.
>
>Thanks again,
>
>Paul
>
>
>
>
>
>-----Original Message-----
>From: support@insightful.com [mailto:support@insightful.com]
>Sent: Monday, February 04, 2008 3:20 PM
>To: Gross, Paul
>Subject: Incident #98154: commandArgs in S-plus
>
>Hello Paul,
>
>Thank you for your question regarding commandArgs().
>
>Unfortunately, as you have found commandArgs() does not work. There is
>a bug report filed to report this behavior. I have added your name and
>comments from your email to the bug report.
>
>There are two options that you can use as a workaround, both involving
>SBATCH:
>
>1. Create an environment variable to hold the parameter values:
>
>For example, in the bash shell:
>
>export MYDATA="parameters"
>
>or in csh shell:
>
>setenv MYDATA="parameters"
>
>Then, you can call getenv() inside of the script file you are calling.
>For example, if I had a file named infile.q, I would add the line:
>
>args <- getenv("MYDATA")
>
>to extract the environment variable value. Then, I would run the
>following at command line:
>
>> Splus SBATCH infile.q outfile.q
>
>to read in and run the infile.q file.
>
>2. Create a file of the parameters and read it in the infile.q
>
>For example, create file:
>
>> echo parameters > test.in
>
>Then, inside of infile.q call:
>
>x <- scan("test.in", what=<specify param_type>)
>
>Finally, we would run the following at the command prompt:
>
>Splus SBATCH infile.q outfile.q
>
>You can read more about SBATCH by typing the following at your S-PLUS
>command
>prompt:
>
>> ?SBATCH
>
>I hope this information is helpful! Please let me know if you have any
>questions.
>
>Sincerely,
>
>Rachel Flodin
>
>=======================================================================
>=
>=
> Rachel Flodin email:
support@insightful.com
> Technical Support Engineer FAX: (206) 283-8691
> Insightful Corporation Phone: (206) 283-8802 ext.235
> www.insightful.com 1-800-569-0123
ext.235
>
>=======================================================================
>=
>=
>
>In order to improve our service we would appreciate hearing from you.
>Please take a few minutes to complete this short survey.
>http://www.zoomerang.com/survey.zgi?p=WEB226JE6MVRGV
>
>
>>---------------- Original Message ----------------
>> From: Paul Gross
>> Sent: 1/30/2008
>> To: support
>> CC: %4
>> Subject: commandArgs in S-plus
>
>> >This is with regard to:
>>devyxsv010{pgross}=> /usr/local/splus8.0.4/cmd/Splus -e VERSION S-PLUS
>>Version 8.0.4 for Linux 2.4.21, 32-bit : 2007 Master ID created Wed
>>May
>
>>2 11:09:02 PDT 2007 Based on S Version 4, Wed June 2, 07:41:00 EDT
>>1999
>>
>>
>>I run the following at the command line:
>>
>>Splus < myScript ARG
>>
>>where myScript consists of the following:
>>
>>for (arg in commandArgs()){ cat(arg, "\n") }
>>
>>In any version of Splus, this leads to an error, e.g.:
>>
>>=> /usr/local/splus8.0.4/cmd/Splus < myScript ARG
>>/usr/local/splus8.0.4/cmd/Splus: line 290: exec: ARG: not found
>>
>>Does this not work in S-plus? The documenation says:
>>
>>TITLE:
>> Function commandArgs
>>
>>USAGE:
>> commandArgs()
>>
>>ARGUMENTS:
>>
>>DESCRIPTION:
>>
>>
>> returns the command-line invoking this S session, as a
>character
>> vector.The first element is the name by which the S executable
>>was
>> invoked; the remainingelements, if any, are the arguments on
>the
>> command line.
>>
>>What am I missing?
>>
>>Thanks,
>>Paul
>>
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Glenn Treacy
Sent: Thursday, June 12, 2008 2:12 PM
To: s-news@wubios.wustl.edu
Subject: [S] Passing arguments to a script file called in batch mode
Hi,
Does anyone know whether it is possible to pass arguments to a script
file that is called in batch mode? I am looking for a way of creating a
dynamic script file that can calls different code depending on the the
value of a variable in a batch file. I have a whole series of script
files that are very similar and this was one idea of consolidating them
into one.
Anyone got an idea?
Thanks in advnace,
Glenn
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
THE INFORMATION CONTAINED IN THIS MESSAGE AND ANY ATTACHMENT MAY BE PRIVILEGED,
CONFIDENTIAL, PROPRIETARY OR OTHERWISE PROTECTED FROM DISCLOSURE. If the reader
of this message is not the intended recipient, you are hereby notified that any
dissemination, distribution, copying or use of this message and any attachment
is strictly prohibited. If you have received this message in error, please
notify us immediately by replying to the message and permanently delete it from
your computer and destroy any printout thereof.
--- End Message ---
|