Hello, I need to clarify, Henrique's suggestion worked great for getting the text that I needed via cat(), but I haven't sorted out how to get cat() like output into a variable so I can pass it into the message body variable I am using.
Here is what I mean: x [1] "a" "b" "c" "d" paste(x,collapse='\n') [1] "a\nb\nc\nd" y = paste(x,collapse='\n') cat(y) a b c d This is the problem with 'y' has the msg body: paste("msg = MIMEText('",y,"')",sep="") [1] "msg = MIMEText('a\nb\nc\nd')" This is what I am after (I think!): paste("msg = MIMEText('",y,"')",sep="") [1] "msg = MIMEText('a b c d')" Here is how I am actually using it (with sensitive items generalized): require(rJython) rJython <- rJython() rJython$exec( "import smtplib" ) rJython$exec("from email.MIMEText import MIMEText") rJython$exec("import email.utils") mail<-c( #Email settings "fromaddr = 'ccqu...@gmail.com'", "toaddrs = 'userna...@somethinghere.com'", #"msg = MIMEText('test message from R')", paste("msg = MIMEText('",y,"')",sep=""), # my message in this example is 'y' "msg['From'] = email.utils.formataddr(('gmail acct', fromaddr))", "msg['To'] = email.utils.formataddr(('cc email!', toaddrs))", "msg['Subject'] = 'test with y'", #SMTP server credentials "username = 'ccqu...@gmail.com'", "password = 'a password here'", #Set SMTP server and send email, e.g., google mail SMTP server "server = smtplib.SMTP('smtp.gmail.com:587')", "server.ehlo()", "server.starttls()", "server.ehlo()", "server.login(username,password)", "server.sendmail(fromaddr, toaddrs, msg.as_string())", "server.quit()") jython.exec(rJython,mail) # and here is the error I get. Error in ls(envir = envir, all.names = private) : invalid 'envir' argument Just in case someone asks, I can do this: y = "a test" ...and the above email sends fine with 'a test' as the msg body. Any ideas? PS - I received lots of suggestions. Thank you very much for your effort/input. Ben On Mon, Aug 29, 2011 at 9:29 PM, Bert Gunter <gunter.ber...@gene.com> wrote: > 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 <ccqu...@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 <www...@gmail.com > >wrote: > > > >> Try: > >> > >> paste(c("a", "b", "c"), collapse = "\n") > >> > >> On Mon, Aug 29, 2011 at 8:56 PM, Ben qant <ccqu...@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@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@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 > [[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.