Skip to content

Commit

Permalink
updated gmailR with manual
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler rinker committed Feb 16, 2013
1 parent 47d9791 commit 5ab74e6
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 130 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
@@ -1,2 +1,6 @@
^\.Rproj\.user$
^.*\.Rproj$
.Rbuildignore
maintenance.R
.gitignore
staticdocs
15 changes: 12 additions & 3 deletions DESCRIPTION
Expand Up @@ -3,9 +3,18 @@ Type: Package
Title: Send gmail With Attachment Via R
Version: 1.0
Date: 2012-08-29
Author: Tyler Rinker
Author: Tyler Rinker and Daniel Malter
Maintainer: Tyler Rinker <tyler.rinker@gmail.com>
Depends: R (>= 2.15.0), rJython
Depends:
R (>= 2.15.0),
rJython
ByteCompile: yes
Description: Send emails with attachments via R.
License: GPL-2
URL: http://github.com/trinker/gmailR
License: GPL-2
Collate:
'cell2email.R'
'email.helper.R'
'gmail.R'
'scrape.cell.R'
'zzz.R'
9 changes: 7 additions & 2 deletions NAMESPACE
@@ -1,3 +1,8 @@
export(email)
export(cell2email)
import(rJython)
export(gmail)
export(scrape.cell)
import(RCurl)
import(rJava)
import(rjson)
import(rJython)
import(XML)
29 changes: 24 additions & 5 deletions R/cell2email.R
@@ -1,19 +1,38 @@
#' Generate an Email from a Cell Phone Number
#'
#' Generates an email adress based on cell number nad carrier.
#'
#' @param cell.number The 10 digits number of the cell you're trying to send a
#' text to.
#' @param carrier The name of the carrier. If NULL interactive selection of a
#' carrier is used.
#' @param omit.old logical. If TRUE removes all the old Canadian carriers from
#' the list.
#' @export
#' @examples
#' cell2email("555-555-5555")
cell2email <-
function(cell.number, carrier, omit.old = TRUE) {
function(cell.number, carrier = NULL, omit.old = TRUE) {
cell.number <- gsub("[^\\d]+", "", cell.number, perl=TRUE)
if(nchar(as.character(cell.number)) != 10) {
stop("cell.number must have 10 digits")
}
x <- cell.ext
if (omit.old) {
x <- x[x[, 3] != "old_us_can", ]
}
y <- tolower(x[, 1]) %in% tolower(carrier)
if (sum(y) == 0) {
cat("\n","Warning: Carrier Not Found!","\n")
if (!is.null(carrier)){
y <- tolower(x[, 1]) %in% tolower(carrier)
if (sum(y) == 0){
cat("\n","Warning: Carrier Not Found!","\n")
carrier <- NULL
}
}
if (is.null(carrier)) {
cat("\n","Choose Carrier","\n")
c2 <- menu(unique(x[, 1]))
y <- tolower(x[, 1]) %in% tolower(x[c2, 1])
}
}
if (sum(y) > 1) {
z <- x[y, ]
cat("\n","Choose Carrier","\n")
Expand Down
1 change: 0 additions & 1 deletion R/email.helper.R
Expand Up @@ -17,7 +17,6 @@ function(to, from, subject, username, password, server, message, attachment,
if (!is.null(attachment)) if (!file.exists(attachment)) stop(paste("'", attachment, "' does not exist!", sep=""))
if (missing(username)) username <- winDialogString("Please enter your e-mail username", "")
if (missing(password)) password <- winDialogString("Please enter your e-mail password", "")
require(rJython)
rJython <- rJython()
rJython$exec("import smtplib")
rJython$exec("import os")
Expand Down
26 changes: 25 additions & 1 deletion R/email.R → R/gmail.R
@@ -1,4 +1,28 @@
email <-
#' Email With Attachments
#'
#' Send emails (including gmails) with attachments from within R.
#'
#' @param to The recipient's email address.
#' @param password Yor password.
#' @param subject The message (default is \code{R message}).
#' @param message The subject line (default is \code{EOM}).
#' @param from Your email address (gmailR will try to store this information for you).
#' @param attachment Path to an attachment you wish to include.
#' @param server email server.
#' @param username Your email address (gmailR will try to store this information for you).
#' @param confirmBeforeSend logical. If TRUE gmail will confirm before sending.
#' @param clear.username logical. If TRUE clears the stored username.
#' @author Tyler Rinker<tyler.rinker@@gmail.com> and Daniel Malter
#' @references \url{http://r.789695.n4.nabble.com/Email-out-of-R-code-td3530671.html}
#' @export
#' @import rJython rJava rjson
#' @examples
#' \dontrun{
#' gmail(to=c("bob@@gmail.com", "janr@@hotmail.com"), password = "password",
#' attachment="path/to/file.pdf")
#' gmail(to=cell2email(5555555555, "sprint"), password = "password")
#' }
gmail <-
function(to, password, subject="R message", message="EOM", from=NULL,
attachment=NULL, server="smtp.gmail.com:587", username=NULL,
confirmBeforeSend=FALSE, clear.username = FALSE){
Expand Down
18 changes: 13 additions & 5 deletions R/scrape.cell.R
@@ -1,8 +1,16 @@
scrape.cell <- function() {
library(RCurl)
library(XML)
url <- "http://www.emailtextmessages.com/"
doc <- htmlTreeParse(url, useInternalNodes=TRUE)
#' Scrape Cell Phone Extensions
#'
#' Grabs cell phone extensions from http://www.emailtextmessages.com/
#'
#' @param URL The URL of the cell phone extension website to scrape from.
#' @export
#' @import RCurl XML
#' @examples
#' \dontrun{
#' scrape.cell()
#' }
scrape.cell <- function(URL = "http://www.emailtextmessages.com/") {
doc <- htmlTreeParse(URL, useInternalNodes=TRUE)
x <- sapply(getNodeSet(doc, "//li") [1:217], xmlValue)
y <- sapply(getNodeSet(doc, "//h3"), xmlValue)
z <- rep(c("us_can", "inter", "old_us_can"),
Expand Down
3 changes: 1 addition & 2 deletions R/zzz.R
@@ -1,4 +1,3 @@
.onLoad <- function(libname = find.package("gmailR"),
pkgname = "gmailR") {
.onLoad <- function(libname = find.package("gmailR"), pkgname = "gmailR") {
data(cell.ext, package = "gmailR")
}
14 changes: 14 additions & 0 deletions inst/CITATION
@@ -0,0 +1,14 @@
citHeader("To cite gmailR in publications, please use:")


citEntry(entry = "manual",
title = "{gmailR}: gmail for {R}",
author = "Tyler W. Rinker",
organization = "University at Buffalo/SUNY",
address = "Buffalo, New York",
note = "version 0.1.0",
year = "2013",
textVersion = paste("Rinker, T. W. (2013).",
"gmailR: gmail for R.",
"version 0.1.0. University at Buffalo. Buffalo, New York.")
)
4 changes: 4 additions & 0 deletions inst/maintenance.R
@@ -0,0 +1,4 @@
#========================
#update data for cell
#========================
cell.ext <- scrape.cell()
24 changes: 0 additions & 24 deletions man/anRpackage-package.Rd

This file was deleted.

15 changes: 0 additions & 15 deletions man/cell.ext.Rd

This file was deleted.

34 changes: 15 additions & 19 deletions man/cell2email.Rd
@@ -1,28 +1,24 @@
\name{cell2email}
\alias{cell2email}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Convert a Cell Phone Number to an Email Address
}
\description{
Convert a cell number to an email address.
}
\title{Generate an Email from a Cell Phone Number}
\usage{
cell2email(cell.number, carrier, omit.old = TRUE)
cell2email(cell.number, carrier = NULL, omit.old = TRUE)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{cell.number}{
10 digit cell phone number
}
\item{carrier}{
Cell phone carrier
}
\item{omit.old}{
logical. Should the old_us_can of the last column of cell.ext data set be used.
\item{cell.number}{The 10 digits number of the cell
you're trying to send a text to.}
\item{carrier}{The name of the carrier. If NULL
interactive selection of a carrier is used.}
\item{omit.old}{logical. If TRUE removes all the old
Canadian carriers from the list.}
}
\description{
Generates an email adress based on cell number nad
carrier.
}
\examples{
cell2email(5555555555, "Sprint")
cell2email(5555555555, "seprint")
cell2email("555-555-5555")
}
53 changes: 0 additions & 53 deletions man/email.Rd

This file was deleted.

54 changes: 54 additions & 0 deletions man/gmail.Rd
@@ -0,0 +1,54 @@
\name{gmail}
\alias{gmail}
\title{Email With Attachments}
\usage{
gmail(to, password, subject = "R message",
message = "EOM", from = NULL, attachment = NULL,
server = "smtp.gmail.com:587", username = NULL,
confirmBeforeSend = FALSE, clear.username = FALSE)
}
\arguments{
\item{to}{The recipient's email address.}
\item{password}{Yor password.}
\item{subject}{The message (default is \code{R
message}).}
\item{message}{The subject line (default is \code{EOM}).}
\item{from}{Your email address (gmailR will try to store
this information for you).}
\item{attachment}{Path to an attachment you wish to
include.}
\item{server}{email server.}
\item{username}{Your email address (gmailR will try to
store this information for you).}
\item{confirmBeforeSend}{logical. If TRUE gmail will
confirm before sending.}
\item{clear.username}{logical. If TRUE clears the stored
username.}
}
\description{
Send emails (including gmails) with attachments from
within R.
}
\examples{
\dontrun{
gmail(to=c("bob@gmail.com", "janr@hotmail.com"), password = "password",
attachment="path/to/file.pdf")
gmail(to=cell2email(5555555555, "sprint"), password = "password")
}
}
\author{
Tyler Rinker<tyler.rinker@gmail.com> and Daniel Malter
}
\references{
\url{http://r.789695.n4.nabble.com/Email-out-of-R-code-td3530671.html}
}
20 changes: 20 additions & 0 deletions man/scrape.cell.Rd
@@ -0,0 +1,20 @@
\name{scrape.cell}
\alias{scrape.cell}
\title{Scrape Cell Phone Extensions}
\usage{
scrape.cell(URL = "http://www.emailtextmessages.com/")
}
\arguments{
\item{URL}{The URL of the cell phone extension website to
scrape from.}
}
\description{
Grabs cell phone extensions from
http://www.emailtextmessages.com/
}
\examples{
\dontrun{
scrape.cell()
}
}

0 comments on commit 5ab74e6

Please sign in to comment.