Skip to content

Input to variables - help please

5 messages · Steve Sidney, Luc Villandre, (Ted Harding)

#
Dear list

I have managed to write a short program to evaluate data which is inputted
from a csv file using the following

x = read.csv("wms_results.csv", header=TRUE)

All works fine but since I have a number of similar data files which have
different names, I would like the program to allow me to input the file
name, rather than having to edit the program.
string varaiable so that from the keyboard I can input the name.

Also which command can I use to output some text to the monitor as a prompt

Any help would be great and apologies for such a simple question. Thanks

Regards
Steve
#
Steve Sidney wrote:
Hi Steve,

I suspect the choose.files() function could be useful in this setting. 
Also, I've read on this forum that message() or cat() were commonly used 
for a prompt (all taken from Prof. Brian Ripley's reply to "Prompt comes 
too late").

Hope this helps,
#
On 13-May-09 19:49:35, Steve Sidney wrote:
Try:

  NextFile <- readline("Enter the CSV filename:\n")
  x = read.csv(NextFile, header=TRUE)

You will then get a prompt "Enter the CSV filename:"
so enter it. Then it will read it.

Example (from the terminal):

  > NextFile <- readline("Enter the CSV filename:\n")
  Enter the CSV filename:
  ACBDEFG.csv
  > NextFile
  [1] "ACBDEFG.csv"
  >

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-May-09                                       Time: 21:12:19
------------------------------ XFMail ------------------------------
#
Hi Luc

Many thanks for the suggestions.

I will take a look at them as soon as I can.

Are the functions standard or are they part of a function and if so which 
one?

Regards
Steve
----- Original Message ----- 
From: "Luc Villandre" <villandl at dms.umontreal.ca>
To: "Steve Sidney" <sbsidney at mweb.co.za>
Cc: <r-help at r-project.org>
Sent: Wednesday, May 13, 2009 10:10 PM
Subject: Re: [R] Input to variables - help please
Steve Sidney wrote:
Hi Steve,

I suspect the choose.files() function could be useful in this setting.
Also, I've read on this forum that message() or cat() were commonly used
for a prompt (all taken from Prof. Brian Ripley's reply to "Prompt comes
too late").

Hope this helps,
#
Steve Sidney wrote:
Are you asking if they are part of a non-default package? If so, then 
the answer is no: all these functions are included in packages that come 
bundled with a regular installation of the latest version of R (base and 
utils).

Cheers,