Thanks Phil, very helpful and works as advertised.
Any thoughts on the second question? (P.S. for anyone digging this up in the future, there's a comma missing after the formula in lm()) On 24 Sep 2010, at 18:16, Phil Spector wrote: > Michael - > You're doing too much work half the time, and not enough > the other half :-). Try this (untested): > > auto_io = function(data_name,factors){ > resp_data = read.table(data_name, header = TRUE ) > temp_model = lm(formula(paste('y',factors,sep='~')) data = resp_data ) > . . . > > - Phil Spector > Statistical Computing Facility > Department of Statistics > UC Berkeley > spec...@stat.berkeley.edu > > > On Fri, 24 Sep 2010, Michael Hopkins wrote: > >> >> >> Hi all >> >> A couple of questions about string processing from someone who has only >> scratched the surface so far. >> >> 1) I am wanting to send some strings into a function to allow flexibility >> inside. My first idea has been e.g. >> >> auto_io <- function( var_string, factors ) { >> # e.g. var_string sent as "test_file.txt" factors sent as "x1 + x2 + x3" >> >> # input >> data_name <- get( var_string ) >> >> # term_list <- get( factors ) >> >> resp_data <- read.table( data_name, >> header = TRUE ) >> >> # fit >> temp_model <- lm( y ~ factors, data = resp_data ) >> >> etc... >> >> Neither the read.table() nor the lm() are working because in each case the >> string is not converted or understood properly. I'm sure this is possible >> (and in fact probably easy) but haven't yet seen the light. Could someone >> illuminate me here? >> >> 2) I will be wanting to process strings as lists of strings. For instance, >> I might instead want to send factors above as "x1 x2 x3" and add the "+" >> when I need them, or perhaps "*" instead, and also look at sub-models by >> removing parts of the string etc. What functions should I be looking at >> here and are there any examples available? >> >> Thanks in advance. Feel free to CC me on your reply. >> >> >> Michael Hopkins >> Algorithm and Statistical Modelling Expert >> >> Upstream >> 23 Old Bond Street >> London >> W1S 4PZ >> >> Mob +44 0782 578 7220 >> DL +44 0207 290 1326 >> Fax +44 0207 290 1321 >> >> hopk...@upstreamsystems.com >> www.upstreamsystems.com >> >> IMPORTANT NOTICE >> The information in this e-mail and any attached files is...{{dropped:22}} >> >> ______________________________________________ >> R-help@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. >> Michael Hopkins Algorithm and Statistical Modelling Expert Upstream 23 Old Bond Street London W1S 4PZ Mob +44 0782 578 7220 DL +44 0207 290 1326 Fax +44 0207 290 1321 hopk...@upstreamsystems.com www.upstreamsystems.com IMPORTANT NOTICE The information in this e-mail and any attached files is CONFIDENTIAL and may be legally privileged or prohibited from disclosure and unauthorised use. The views of the author may not necessarily reflect those of Upstream S.A. It is intended solely for the addressee, or the employee or agent responsible for delivering such materials to the addressee. If you have received this message in error please return it to the sender then delete the email and destroy any copies of it. If you are not the intended recipient, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication, or any action taken or omitted to be taken in reliance upon this message or its attachments is prohibited and may be unlawful. At present the integrity of e-mail across the Internet cannot be guaranteed and messages sent via this medium are potentially at risk. All liability is excluded to the extent permitted by law for any claims arising as a result of the u! se of this medium to transmit information by or to Upstream S.A. [[alternative HTML version deleted]] ______________________________________________ R-help@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.