[R] R Script Help!

Sarah Goslee sarah.goslee at gmail.com
Wed Jun 22 01:14:57 CEST 2011


Hi,

So is your actual question about how to prompt for user input, rather
than anything about the SQL extraction or graphing?

I think I would write the R code as a function that takes the four
values as arguments. That's not  the same as prompting the user, but
more flexible and more R-ish.

You could also try readline() for getting input. If you search the
mailing list archives, that question comes up fairly regularly.

I've taken the liberty of copying this to the R-help list in case
someone else has more suggestions. You need to choose "reply all" and
not just "reply" for that to happen.

Sarah

On Tue, Jun 21, 2011 at 6:19 PM,  <george at leadbetter.cc> wrote:
> Hi Sarah,
>
> Thanks for your response. I understand now my question is phrased very
> poorly. I think this is what I should have said.
>
> 1) My problem - I have a database in SQL and access to R. I want to write to
> write a script to generate a graph using information from the SQL database.
> What I really want is the user of the script to be prompted for 4 pieces of
> information: a start date, a finish date, and 2 product codes related to the
> datbase. I want to take these 4 inputs, which define the data I need from
> the database and use this data to generate the graph.
>
> 2) what i currently and doing is the following. I have opened an R text file
> and used the commandArgs function to generate my query and produce my graph.
> This has to be run through a terminal window. I'm using a Mac, so I type
> into the terminal window, Rscript filename.R --from "2011-05-01" --to
> "2011-06-01"  etc. So the user isn't prompted for the arguments you have to
> know them. I've made it so that if you just type Rscript filename.R into the
> terminal and execute then it returns a help message which shows you what to
> do.
>
> These args are then manipulated in this text file so that they can be put
> into an SQLquery embedded in the text file, the data I want is then
> extracted and from this the graphs are generated.
>
> I'm not sure my use of the term R text file is correct. What I refer to as
> an R text file is what you get when you click the blank page icon at the
> presented at the top of the screen on an R console window.
>
> The way I have gone about solving my problem seems unnecessarily long winded
> to me and I know there are significantly easier ways of going about similar
> tasks in Matlab (which I no longer have access to). I was hoping you could
> point me in the right direction.
>
> Many thanks,
> George Leadbetter
>
> Quoting Sarah Goslee <sarah.goslee at gmail.com>:
>
>> Hi George,
>>
>> On Tue, Jun 21, 2011 at 9:33 AM, george at leadbetter.cc
>> <george at leadbetter.cc> wrote:
>>>
>>> I have written a script in an R text file that i can run through a
>>> terminal
>>> window. My script though contains lots of code to interpret my input
>>> arguments, which are then put into an SQL query to get the data I want to
>>> plot some graphs. The script works, but there must be an easier way to do
>>> what I want using maybe Rscript or something else but I can't seem to
>>> find
>>> it! Any help would be much appreciated.
>>
>> There's almost certainly an easier way, or several, but we don't know
>> what you're doing, or what you want.
>>
>> You've written a script. It has code in it. It works.
>>
>> And?
>>
>> Obviously somehow you're running it. We don't know how.
>>
>> Something is more complicated than you'd like. We don't know what.
>>
>> You've looked for more ideas. We don't know what about.
>>
>> Sarah
>>
>>> Thanks,
>>> George
>>>
>>
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org
>>
>
>
>
>



More information about the R-help mailing list