[R] Pass Conditional & loop argument into a function

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Aug 8 19:13:39 CEST 2012


The quotes shown on a string when you print it are artifacts of making the string usable in source code... they are not present in the string as it is stored in memory. (Same goes for escape sequences, such that "\n" occupies one byte of UTF8 storage.)

You can use the cat function to send the string directly to the output stream to prove this to yourself.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

"greatest.possible.newbie" <daniel.hoop at gmx.net> wrote:

>Thank you for your improvement suggestions.
>I forgot to write the I() and it's clear that I have to specify the
>data
>(which I was indicating with the '...' without explicitly writing it).
>
>In this special case where I need a formula you really helped me with
>the
>function as.formula() to transform the character string into a formula.
>But
>what if I want to insert something else (not necessarily an object of
>the
>class formula)? 
>
>What I really need is something to remove the "" from the character
>string.
>I already read things about eval(), substitute(), parse(text=...),
>assign()
>and get() but that doesn't really help in my case or at least I don't
>know
>to handle it the way I would need it.
>
>Example:
>foo <- function(data, variable.argument="data[,1],data[,2]") {
>*variable.argument <- function that removes "" (variable.argument)*
>cbind(variable.argument)
>}
>
>Normally the variable.argument is defined inside of the function as I
>did it
>with the formula (my 1st question).
>
>I hope you understand what I mean and thank you for your help!
>Regards
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Pass-Conditional-loop-argument-into-a-function-tp4639580p4639637.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>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.



More information about the R-help mailing list