Skip to content

Commit

Permalink
v0.0.3 -- added a messages_info() function that allows you to easily …
Browse files Browse the repository at this point in the history
…extract the basic information from a gmail_messages object
  • Loading branch information
lcolladotor committed Sep 5, 2014
1 parent 9a7ab39 commit 8861775
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: gmailr
Version: 0.0.2
Version: 0.0.3
Date: 2014-09-05
Maintainer: Jim Hester <james.f.hester@gmail.com>
Author: Jim Hester
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(label)
export(labels)
export(message)
export(messages)
export(messages_info)
export(modify_message)
export(modify_thread)
export(save_attachment)
Expand Down
44 changes: 44 additions & 0 deletions R/message.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,50 @@ messages = function(search = NULL, num_results = NULL, label_ids = NULL, include
page_and_trim('messages', user_id, num_results, search, page_token, label_ids, include_spam_trash)
}

#' Extract information from a list of messages
#'
#' Extract the message ids, thread ids, the next page token or the result size
#' estimate from a \code{gmail_messages} object created with \link{messages}.
#'
#' @param messages The output from \link{messages}.
#' @param what Either \code{'id'}, \code{'threadId'}, \code{'nextPageToken'},
#' \code{'resultSizeEstimate'}.
#'
#' @return For \code{what = 'id'} or \code{what = 'threadId'} a vector with the
#' message ids or thread ids, respectively. Otherwise the next page token or
#' result size estimate information.
#'
#' @export
#' @author L. Collado-Torres <lcollado@@jhu.edu>
#' @seealso \link{messages}
#'
#' @examples
#' \dontrun{
#' #Search for R, return 10 results using label 1 including spam and trash folders
#' my_messages = messages("R", 10, "label_1", TRUE)
#'
#' ## Extract the ids from the messages
#' ids <- messages_info(my_messages)
#'
#' ## You can then use these ids as input for other functions.
#' }

messages_info <- function(messages, what = 'id') {
## Check inputs
stopifnot(class(messages) == 'gmail_messages')
stopifnot(what %in% c('id', 'threadId', 'nextPageToken', 'resultSizeEstimate'))

## Extract the required info
if(what %in% c('id', 'threadId')) {
result <- sapply(messages[[1]]$messages, '[[', what)
} else {
result <- messages[[1]][[what]]
}

## Done
return(result)
}

#' Send a single message to the trash
#'
#' Function to trash a given message by id. This can be undone by \code{\link{untrash_message}}.
Expand Down
40 changes: 40 additions & 0 deletions man/messages_info.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{messages_info}
\alias{messages_info}
\title{Extract information from a list of messages}
\usage{
messages_info(messages, what = "id")
}
\arguments{
\item{messages}{The output from \link{messages}.}

\item{what}{Either \code{'id'}, \code{'threadId'}, \code{'nextPageToken'},
\code{'resultSizeEstimate'}.}
}
\value{
For \code{what = 'id'} or \code{what = 'threadId'} a vector with the
message ids or thread ids, respectively. Otherwise the next page token or
result size estimate information.
}
\description{
Extract the message ids, thread ids, the next page token or the result size
estimate from a \code{gmail_messages} object created with \link{messages}.
}
\examples{
\dontrun{
#Search for R, return 10 results using label 1 including spam and trash folders
my_messages = messages("R", 10, "label_1", TRUE)

## Extract the ids from the messages
ids <- messages_info(my_messages)

## You can then use these ids as input for other functions.
}
}
\author{
L. Collado-Torres <lcollado@jhu.edu>
}
\seealso{
\link{messages}
}

0 comments on commit 8861775

Please sign in to comment.