[R] output without quotes

David Winsemius dwinsemius at comcast.net
Fri Jul 9 22:20:51 CEST 2010


On Jul 9, 2010, at 3:51 PM, AC Del Re wrote:

> Hi All,
>
> I am interested in printing column names without quotes and am  
> struggling to
> do it properly. The tough part is that I am interested in using  
> these column
> names for a function within a function (e.g., lm() within a wrapper
> function). Therefore, cat() doesnt seem appropriate

> and print() is not what I need. Ideas?

My idea is that you need to show the code you hope to write so that  
the appropriate language elements can be constructed. If it's going  
into a formula there might be one answer whereas if it's going to be  
used to access columns in a subset expression it may be another method.

>
> # sample data
> mod1 <- rnorm(20, 10, 2)
> mod2 <- rnorm(20, 5, 1)
> dat <- data.frame(mod1, mod2)
>
> # collapsing the colnames to 'mod1+mod2'
> temp <- paste(names(dat), collapse="+")
>
> temp  # this gives quotes
> print(temp, quote = FALSE)  # no quotes but includes [1]
>
> # need the output like this (no quotes & no [1]):    mod1+mod2

Which cat _would_ print on the device or file but it not return  
anything to the interpreter for further evaluation.
-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list