From ffca5e0ef7654ecd22e87b384ffc74fe732648fe Mon Sep 17 00:00:00 2001 From: Jim Hester Date: Sun, 10 Mar 2019 10:50:33 -0500 Subject: [PATCH] Fix R CMD check issues --- .Rbuildignore | 10 ++++-- DESCRIPTION | 13 +++++--- LICENSE | 23 ++------------ LICENSE.md | 21 ++++++++++++ NAMESPACE | 14 +++++++- R/duplicates.R | 29 ++++++++--------- R/form_intake.R | 6 ---- R/get_tweets.R | 44 +++++++++++--------------- R/run_pipleine.R | 12 ++----- R/score_tweets.R | 1 + R/utils-pipe.R | 11 +++++++ R/utils.R | 3 ++ R/zzz.R | 17 +++++----- man/add_rstats_hashtag.Rd | 10 +++--- man/filter_dupes.Rd | 4 ++- man/get_tweet_number.Rd | 3 -- man/get_tweets.Rd | 2 +- man/pipe.Rd | 12 +++++++ man/retrieveSubmissions.Rd | 16 ++++++++++ man/save_tweet_number.Rd | 5 +-- man/save_tweets.Rd | 2 +- man/{close_tips.Rd => similar_text.Rd} | 10 +++--- 22 files changed, 154 insertions(+), 114 deletions(-) create mode 100644 LICENSE.md create mode 100644 R/utils-pipe.R create mode 100644 R/utils.R create mode 100644 man/pipe.Rd create mode 100644 man/retrieveSubmissions.Rd rename man/{close_tips.Rd => similar_text.Rd} (70%) diff --git a/.Rbuildignore b/.Rbuildignore index 8556b4b..b3a17c1 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,5 +1,11 @@ +^.*\.xlsx$ +^.*\.zip$ ^CODE_OF_CONDUCT\.md$ -^data-raw$ -^rlangtip\.Rproj$ +^Categories\.md$ +^Contributions\.md$ +^LICENSE\.md$ ^\.Rproj\.user$ ^\.httr-oauth$ +^data-raw$ +^n_tweets\.txt$ +^rlangtip\.Rproj$ diff --git a/DESCRIPTION b/DESCRIPTION index ce77659..e626804 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,12 +2,12 @@ Package: rlangtip Title: What the Package Does (One Line, Title Case) Version: 0.0.0.9000 Authors@R: - person(given = "First", - family = "Last", + person(given = "David", + family = "Smith", role = c("aut", "cre"), email = "first.last@example.com") Description: What the package does (one paragraph). -License: What license it uses +License: MIT + file LICENSE Encoding: UTF-8 LazyData: true Suggests: @@ -21,6 +21,11 @@ Imports: tidyr, spelling, stringdist, + tibble, readr, - tibble + readxl, + dplyr, + magrittr, + stringr, + cowsay RoxygenNote: 6.1.1 diff --git a/LICENSE b/LICENSE index 8e3de01..3780bfd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,2 @@ -MIT License - -Copyright (c) 2019 David Smith - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +YEAR: 2019 +COPYRIGHT HOLDER: David Smith diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1c89387 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2019 David Smith + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE index e929d22..f397c0d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,11 +1,23 @@ # Generated by roxygen2: do not edit by hand +export("%>%") export(add_rstats_hashtag) export(check_tip_spelling) -export(close_tips) export(filter_dupes) export(get_tweet_number) export(get_tweets) +export(retrieveSubmissions) export(run_tweet_pipeline) export(save_tweet_number) export(save_tweets) +export(similar_text) +importFrom(dplyr,"%>%") +importFrom(dplyr,as_tibble) +importFrom(dplyr,case_when) +importFrom(dplyr,distinct) +importFrom(dplyr,enquo) +importFrom(dplyr,filter) +importFrom(dplyr,mutate) +importFrom(dplyr,rename) +importFrom(dplyr,select) +importFrom(magrittr,"%>%") diff --git a/R/duplicates.R b/R/duplicates.R index 57bef0a..c89fab6 100644 --- a/R/duplicates.R +++ b/R/duplicates.R @@ -1,35 +1,32 @@ #' Return a table of close tips #' -#' @param tips data.frame of tips -#' @param cutoff the cutoff to use +#' @param text data.frame of tips +#' @param cutoff the Z score cutoff to use #' @inheritParams stringdist::stringdistmatrix #' @param ... Additional parameters passed to [stringdist::stringdistmatrix] #' @export -close_tips <- function(tips, cutoff = 0.15, method = "jw", ...) { - diffs <- stringdist::stringdistmatrix(tips$Tip, tips$Tip, method = method) +similar_text <- function(text, cutoff = -3, method = "jw", ...) { + diffs <- stringdist::stringdistmatrix(text, text, method = method) diffs[lower.tri(diffs, diag = TRUE)] <- NA close <- which(diffs < cutoff) tibble::tibble( tip_1_id = col(diffs)[close], tip_2_id = row(diffs)[close], - score = diffs[close], - tip_1 = tips$Tip[tip_1_id], - tip_2 = tips$Tip[tip_2_id] + score = z_score(diffs)[close], + tip_1 = text[tip_1_id], + tip_2 = text[tip_2_id] ) } - - +utils::globalVariables(c("tip_1_id", "tip_2_id")) #' Filter Dupes #' -#' @param tbl -#' @param cutoff +#' @param tbl A tibble +#' @param cutoff The Z-score cutoff to use for filtering #' -#' @return #' @export -#' -#' @examples +#' @importFrom dplyr as_tibble rename filter mutate distinct select filter_dupes <- function(tbl, cutoff = -3) { dists <- expand.grid(tbl$text, tbl$text) %>% @@ -41,7 +38,7 @@ filter_dupes <- function(tbl, cutoff = -3) { filter(tweet_1 != tweet_2) %>% mutate( string_dist = stringdist::stringdist(tweet_1, tweet_2), - string_dist_scaled = dobtools::z_score(string_dist) + string_dist_scaled = z_score(string_dist) ) %>% filter( string_dist_scaled > cutoff @@ -52,3 +49,5 @@ filter_dupes <- function(tbl, cutoff = -3) { text = tweet_1 ) } +utils::globalVariables(c("Var1", "Var2", "tweet_1", "tweet_2", "string_dist", + "string_dist_scaled")) diff --git a/R/form_intake.R b/R/form_intake.R index 234784f..15bc27d 100644 --- a/R/form_intake.R +++ b/R/form_intake.R @@ -3,14 +3,8 @@ #' @param key Character. The key value associated with the google sheet which has the form responses. #' @param tab Character. Name of the google sheet tab with the form responses. #' -#' @return #' @export #' -#' @examples -#' -#' -#' - retrieveSubmissions <- function(key, tab) { rLangSheet <- googlesheets::gs_key(key) rLangSheet %>% diff --git a/R/get_tweets.R b/R/get_tweets.R index 79bedd3..2a14a50 100644 --- a/R/get_tweets.R +++ b/R/get_tweets.R @@ -4,10 +4,8 @@ #' #' @param buffer Numeric. The number to add to the last number of tweets pulled in such that we always ask for more tweets than necessary the next time the script is run. #' -#' @return #' @export -#' -#' @examples +#' @importFrom dplyr %>% #' get_tweet_number <- function(buffer = 100) { last_val <- @@ -19,26 +17,18 @@ get_tweet_number <- function(buffer = 100) { #' Save tweet number #' -#' @param val +#' @param val the vector of tweet numbers #' -#' @return #' @export #' -#' @examples -#' - save_tweet_number <- function(val) { readr::write_lines(val, n_tweets_path) } #' Get Tweets #' -#' @param save_number -#' -#' @return +#' @param save_number Whether to save the numbers of the tweets or not #' @export -#' -#' @examples get_tweets <- function(save_number = TRUE) { n_tweets_to_grab <- get_tweet_number() @@ -53,30 +43,32 @@ get_tweets <- function(save_number = TRUE) { tbl %>% select(status_id, created_at, text, favorite_count, retweet_count) } +utils::globalVariables(c("status_id", "created_at", "text")) #' Add #rstats #' -#' @param txt Tip text. +#' @param tbl Tip text. #' @param col Column to add hashtags to. #' -#' @return #' @export #' +#' @importFrom dplyr enquo case_when #' @examples #' -#' tibble(text = "foo") %>% add_rstats_hashtag() -#' tibble(text = "foo #rstats") %>% add_rstats_hashtag +#' tibble::tibble(text = "foo") %>% add_rstats_hashtag(text) +#' tibble::tibble(text = "foo #rstats") %>% add_rstats_hashtag(text) #' -add_rstats_hashtag <- function(tbl, col = text) { - q_col <- enquo(col) +add_rstats_hashtag <- function(tbl, col) { - tbl %>% - mutate( - text = - case_when( - !str_detect(!!q_col, "#rstats") ~ !!q_col %>% str_c(" #rstats"), - TRUE ~ text - ) + q_col <- enquo(col) + + tbl %>% + mutate( + text = + case_when( + ! stringr::str_detect(!!q_col, "#rstats") ~ !!q_col %>% stringr::str_c(" #rstats"), + TRUE ~ text ) + ) } diff --git a/R/run_pipleine.R b/R/run_pipleine.R index 48c5733..9afe42c 100644 --- a/R/run_pipleine.R +++ b/R/run_pipleine.R @@ -1,25 +1,17 @@ - - #' Save Tweets #' -#' @param tbl +#' @param tbl a tibble of tweets #' -#' @return #' @export -#' -#' @examples save_tweets <- function(tbl) { # Will be whatever format Jim decides - write_csv(tbl, tips_path) + readr::write_csv(tbl, tips_path) } #' Get, score, and save tweets #' -#' @return #' @export -#' -#' @examples run_tweet_pipeline <- function() { get_tweets() %>% score_tweets() %>% diff --git a/R/score_tweets.R b/R/score_tweets.R index 5216616..85a2136 100644 --- a/R/score_tweets.R +++ b/R/score_tweets.R @@ -1,4 +1,5 @@ +utils::globalVariables(c("favorite_count", "retweet_count")) score_tweets <- function(tbl) { tbl %>% diff --git a/R/utils-pipe.R b/R/utils-pipe.R new file mode 100644 index 0000000..fb8c818 --- /dev/null +++ b/R/utils-pipe.R @@ -0,0 +1,11 @@ +#' Pipe operator +#' +#' See \code{magrittr::\link[magrittr]{\%>\%}} for details. +#' +#' @name %>% +#' @rdname pipe +#' @keywords internal +#' @export +#' @importFrom magrittr %>% +#' @usage lhs \%>\% rhs +NULL diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..34cfd38 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,3 @@ +z_score <- function(x) { + (x - mean(x)) / stats::sd(x) +} diff --git a/R/zzz.R b/R/zzz.R index 20121d3..1f2c1c7 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,15 +1,14 @@ - n_tweets_path <- here::here("n_tweets.txt") tips_path <- here::here("tips.csv") +utils::globalVariables(c("consumer_key", "consumer_secret", "access_token", "access_secret")) save_twitter_token <- function() { - source(here::here(twitter_keys.R)) + source(here::here("twitter_keys.R")) - create_token( - app = "RLangTip", - consumer_key = consumer_key, - consumer_secret = consumer_secret, - acess_token = acess_token, - access_secret = access_secret - ) + rtweet::create_token( + app = "RLangTip", + consumer_key = consumer_key, + consumer_secret = consumer_secret, + access_token = access_token, + access_secret = access_secret) } diff --git a/man/add_rstats_hashtag.Rd b/man/add_rstats_hashtag.Rd index 9fc4503..10acb1e 100644 --- a/man/add_rstats_hashtag.Rd +++ b/man/add_rstats_hashtag.Rd @@ -4,19 +4,19 @@ \alias{add_rstats_hashtag} \title{Add #rstats} \usage{ -add_rstats_hashtag(tbl, col = text) +add_rstats_hashtag(tbl, col) } \arguments{ -\item{col}{Column to add hashtags to.} +\item{tbl}{Tip text.} -\item{txt}{Tip text.} +\item{col}{Column to add hashtags to.} } \description{ Add #rstats } \examples{ -tibble(text = "foo") \%>\% add_rstats_hashtag() -tibble(text = "foo #rstats") \%>\% add_rstats_hashtag +tibble::tibble(text = "foo") \%>\% add_rstats_hashtag(text) +tibble::tibble(text = "foo #rstats") \%>\% add_rstats_hashtag(text) } diff --git a/man/filter_dupes.Rd b/man/filter_dupes.Rd index 5b239cf..d86b2c5 100644 --- a/man/filter_dupes.Rd +++ b/man/filter_dupes.Rd @@ -7,7 +7,9 @@ filter_dupes(tbl, cutoff = -3) } \arguments{ -\item{cutoff}{} +\item{tbl}{A tibble} + +\item{cutoff}{The Z-score cutoff to use for filtering} } \description{ Filter Dupes diff --git a/man/get_tweet_number.Rd b/man/get_tweet_number.Rd index 1686e68..db1a118 100644 --- a/man/get_tweet_number.Rd +++ b/man/get_tweet_number.Rd @@ -12,6 +12,3 @@ get_tweet_number(buffer = 100) \description{ Get tweet number } -\examples{ - -} diff --git a/man/get_tweets.Rd b/man/get_tweets.Rd index bc49133..671bb34 100644 --- a/man/get_tweets.Rd +++ b/man/get_tweets.Rd @@ -7,7 +7,7 @@ get_tweets(save_number = TRUE) } \arguments{ -\item{save_number}{} +\item{save_number}{Whether to save the numbers of the tweets or not} } \description{ Get Tweets diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..b7daf6a --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\description{ +See \code{magrittr::\link[magrittr]{\%>\%}} for details. +} +\keyword{internal} diff --git a/man/retrieveSubmissions.Rd b/man/retrieveSubmissions.Rd new file mode 100644 index 0000000..64fb760 --- /dev/null +++ b/man/retrieveSubmissions.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/form_intake.R +\name{retrieveSubmissions} +\alias{retrieveSubmissions} +\title{Import Google Sheets Data} +\usage{ +retrieveSubmissions(key, tab) +} +\arguments{ +\item{key}{Character. The key value associated with the google sheet which has the form responses.} + +\item{tab}{Character. Name of the google sheet tab with the form responses.} +} +\description{ +Import Google Sheets Data +} diff --git a/man/save_tweet_number.Rd b/man/save_tweet_number.Rd index a043434..cf4c763 100644 --- a/man/save_tweet_number.Rd +++ b/man/save_tweet_number.Rd @@ -7,11 +7,8 @@ save_tweet_number(val) } \arguments{ -\item{val}{} +\item{val}{the vector of tweet numbers} } \description{ Save tweet number } -\examples{ - -} diff --git a/man/save_tweets.Rd b/man/save_tweets.Rd index b66fcda..e0d4d4c 100644 --- a/man/save_tweets.Rd +++ b/man/save_tweets.Rd @@ -7,7 +7,7 @@ save_tweets(tbl) } \arguments{ -\item{tbl}{} +\item{tbl}{a tibble of tweets} } \description{ Save Tweets diff --git a/man/close_tips.Rd b/man/similar_text.Rd similarity index 70% rename from man/close_tips.Rd rename to man/similar_text.Rd index c9e7366..f98a956 100644 --- a/man/close_tips.Rd +++ b/man/similar_text.Rd @@ -1,15 +1,15 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/duplicates.R -\name{close_tips} -\alias{close_tips} +\name{similar_text} +\alias{similar_text} \title{Return a table of close tips} \usage{ -close_tips(tips, cutoff = 0.15, method = "jw", ...) +similar_text(text, cutoff = -3, method = "jw", ...) } \arguments{ -\item{tips}{data.frame of tips} +\item{text}{data.frame of tips} -\item{cutoff}{the cutoff to use} +\item{cutoff}{the Z score cutoff to use} \item{method}{Method for distance calculation. The default is \code{"osa"}, see \code{\link{stringdist-metrics}}.}