[R] character vector to text with returns

Bert Gunter gunter.berton at gene.com
Tue Aug 30 05:29:22 CEST 2011


Is something like this what you want?

x <- letters[1:4]
x
y <-do.call(paste,c( paste('"',x[1]), as.list(x[2:3]),
paste(x[4],'"'),sep="\n"))
y
cat(y,"\n")

-- Bert


On Mon, Aug 29, 2011 at 6:59 PM, Ben qant <ccquant at gmail.com> wrote:
> Unfortunately that didn't work. I just says the text is an invalid argument.
> I also tried saving it in a variable name and passed that in, but that
> didn't work. I get:
>
> Error in ls(envir = envir, all.names = private) :
>  invalid 'envir' argument
>
> ...when I try to send the message.
>
> Any other ideas?
>
> Thanks,
> Ben
>
> On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna <wwwhsd at gmail.com>wrote:
>
>> Try:
>>
>> paste(c("a", "b", "c"), collapse = "\n")
>>
>> On Mon, Aug 29, 2011 at 8:56 PM, Ben qant <ccquant at gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Does anyone know how to convert this:
>>> > msg
>>>  [1] "a"
>>>  [2] "b"
>>>  [3] "c"
>>>
>>>
>>> To:
>>>
>>> > msg
>>> "a
>>>  b
>>>  c"
>>>
>>> In other words, I need to convert a character vector to a single string
>>> with
>>> carriage returns for each row.
>>>
>>> Functionally, I'm attempting to send an email of a character vector in a
>>> way
>>> that is readable in the email body. I can only input one string as the
>>> message body parameter. I'm using rJython to send the email because I need
>>> authentication.
>>>
>>> Thanks!
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics



More information about the R-help mailing list