Skip to content

Commit

Permalink
Fix R CMD check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Mar 10, 2019
1 parent 05945ff commit ffca5e0
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 114 deletions.
10 changes: 8 additions & 2 deletions .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$
13 changes: 9 additions & 4 deletions DESCRIPTION
Expand Up @@ -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:
Expand All @@ -21,6 +21,11 @@ Imports:
tidyr,
spelling,
stringdist,
tibble,
readr,
tibble
readxl,
dplyr,
magrittr,
stringr,
cowsay
RoxygenNote: 6.1.1
23 changes: 2 additions & 21 deletions 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
21 changes: 21 additions & 0 deletions 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.
14 changes: 13 additions & 1 deletion 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,"%>%")
29 changes: 14 additions & 15 deletions 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) %>%
Expand All @@ -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
Expand All @@ -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"))
6 changes: 0 additions & 6 deletions R/form_intake.R
Expand Up @@ -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 %>%
Expand Down
44 changes: 18 additions & 26 deletions R/get_tweets.R
Expand Up @@ -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 <-
Expand All @@ -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()
Expand All @@ -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
)
)
}
12 changes: 2 additions & 10 deletions 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() %>%
Expand Down
1 change: 1 addition & 0 deletions R/score_tweets.R
@@ -1,4 +1,5 @@

utils::globalVariables(c("favorite_count", "retweet_count"))

score_tweets <- function(tbl) {
tbl %>%
Expand Down
11 changes: 11 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions R/utils.R
@@ -0,0 +1,3 @@
z_score <- function(x) {
(x - mean(x)) / stats::sd(x)
}
17 changes: 8 additions & 9 deletions 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)
}
10 changes: 5 additions & 5 deletions man/add_rstats_hashtag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/filter_dupes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/get_tweet_number.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ffca5e0

Please sign in to comment.