R/invite_users.R

#' Invite users
#'
#' Invite users to participate
#' @param users
#' @param n The number of users to invite
#' @return Users will be emailed
#' @export

add_user <- function(users,
                     n = NULL,
                     password = '') {
	require(googlesheets)
  require(dplyr)
  require(mailR)

  sender <- 'joebrew@gmail.com'
  the_subject <- 'The malaria elimination prediction market'

  if(is.null(n)){
    n <- nrow(users)
  }

  for (i in 983:n){
    df <- users[i,]

    message('Sending an email to ', df$email, ' (', i, ')')
    body <-
      paste0('Dear ', unlist(lapply(strsplit(df$name, ' '), function(x){x[1]})), ',\n\n',
             'My name is Joe Brew. I am a PhD student doing research on the economics of malaria. I came across your name on PubMed as a fellow malaria researcher, and I would like to invite you to participate in a small economics project of mine.\n\n',
             'I have created a (fake) "prediction market" for malaria elimination. This is an online platform through which people can buy (fake) shares in certain events, similar to the stock market. The idea is that if many experts participate, the "price" of certain events will reflect their probability.\n\n',
             'Would you like to participate? I have already created an account for you (details below). This is just a prototype to assess feasibility, but the more participants, the better the project (and the more accurate the probabilities generated by it).\n\n',
             'The market: ', 'www.economicsofmalaria.com/market\n',
             'Your username: ', df$username, '\n',
             'Your password: ', df$password, '\n\n',
             'I hope you will consider giving this a try. Please do not hesitate to write to me if you have any questions. If you prefer not to or do not have the time, simply ignore this email ( will not bother you again). Thanks!\n\nJoe Brew\njoebrew@gmail.com')
    send.mail(from = sender,
              to = as.character(df$email),
              subject = the_subject,
              body = body,
              smtp = list(host.name = "smtp.gmail.com",
                          port = 465,
                          user.name = sender,
                          passwd=password,
                          ssl=TRUE),
              authenticate = TRUE,
              send = TRUE)
    Sys.sleep(30)
  }
}
joebrew/malariaprediction documentation built on May 15, 2019, 1:40 p.m.