0

I need to attach previous day date in subject of mail using RDCOMClient, tried below code but no luck.

d1=Sys.Date()-1

OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = paste("anc@xyb.com")

outMail[["subject"]] = "Database collection dated" + d1

outMail$Send()

error I received is

Error in "Database collection dated" + "d1" : 
  non-numeric argument to binary operator
MSM
  • 69
  • 7

3 Answers3

1

You maybe looking for paste/paste0 to create a subject line.

outMail[["subject"]] = paste("Database collection dated",  d1)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
1

Problem is that you are trying to actually sum two Strings. You cannot do that in R. Unlike Python or JS, to concatenate two strings in R you should use the paste/paste0 functions. Can you please try and use paste0?

outMail[["subject"]] <- paste0("Database collection dated ", d1)
uceslc0
  • 81
  • 5
1

An option with sprintf

outMail[['subject']] <- sprintf('Database collected dated %s', d1)
akrun
  • 874,273
  • 37
  • 540
  • 662