MSM
MSM

Reputation: 69

How to attach date in subject of mail using RDCOMClient

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("[email protected]")

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

outMail$Send()

error I received is

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

Upvotes: 0

Views: 102

Answers (3)

akrun
akrun

Reputation: 887951

An option with sprintf

outMail[['subject']] <- sprintf('Database collected dated %s', d1)

Upvotes: 1

uceslc0
uceslc0

Reputation: 81

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)

Upvotes: 1

Ronak Shah
Ronak Shah

Reputation: 389325

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

outMail[["subject"]] = paste("Database collection dated",  d1)

Upvotes: 1

Related Questions