在R

时间:2016-05-04 20:23:10

标签: r

首先发布在Stack上。我正在尝试根据我的工作流程中的标准请求创建文件夹和文件。我能够基于campaign_id构建正确的文件结构,但无法找到更改迭代列的方法来为电子邮件提取正确的信息。我已经搜索了几个小时的电路板寻找解决方案,但没有看到一个。我学习了Python中的循环,所以我意识到有一个很简单的方法可以用apply系列做到这一点,我还没有到达那里。

library(sqldf)
library(RODBC)
library(RDCOMClient)

new_campaign <- data.frame(campaign_id = c('001GW','002GW','003GW'), 
                           id = c('111111-1','111111-1','111111-1'), 
                           email = c('no@no.com','no@no.com','no@no.com'))


    #---------------This code works creating files in my dir with the campaign_id-------------------------#
new_dir <- colnames('new_dir')
for(i in new_campaign[,1]){
  setwd(camp_dir)
  if(dir.exists(paste(getwd(),i, sep = '/'))){
    print(paste('Directory For Campaign_ID',i,'Already Exists'))
  } else {
    dir.create(paste(i))
    temp_dir <- paste(getwd(),i, sep = '/')
    mail_list <- sqlQuery(con,("SELECT * FROM table"))
    mail_list$control_ind <- runif(nrow(mail_list), 0, 1)
    mail_list$control_ind <- ifelse(mail_list$control_ind < .1000,'Y','N')
    prod <- subset(mail_list, control_ind = 'N')
    control <- subset(mail_list, control_ind = 'Y')
    setwd(temp_dir)
    write.csv(prod,'prod_email_list.csv', row.names = FALSE)
    write.csv(control,'control_email_list.csv', row.names = FALSE)
    write.csv(mail_list, paste(i,"raw_email_list.csv", sep = '_'),row.names = FALSE)
    new_dir <- rbind(temp_dir, new_dir)
    setwd(camp_dir)
#--------- Now I want to email the requester telling them their file is done but it errors out -----------#    
    OutApp <- COMCreate("Outlook.Application")
    outMail = OutApp$CreateItem(0)
    outMail[["To"]] = new_campaign[i,3] #This is the problem. I want to change the column to 3 to get email address
    outMail[["subject"]] = paste("Your Email List For Campaign",i,"is Ready")
    outMail[["body"]] = "test"
    outMail$Send()
    rm(list = c('temp_dir','mail_list','prod','control'))
  }
}

错误代码:

Error in `[[<-`(`*tmp*`, "To", value = NA_integer_) : 
  Can't attach the RDCOMServer package needed to create a generic COM object
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘RDCOMServer’

0 个答案:

没有答案