diff --git a/DESCRIPTION b/DESCRIPTION index 72495b5..a7c0abe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,15 +18,16 @@ Depends: R (>= 3.5.0) Imports: beepr (>= 1.3), - dplyr (>= 0.7.8), + dplyr (>= 0.8.0), + ellipsis, glue, graphics, imager (>= 0.41.2), magrittr, - purrr (>= 0.3.0), + purrr (>= 0.3.2), rvest (>= 0.3.2), stringr (>= 1.3.1), - tibble (>= 2.0.1) + tibble (>= 2.1.1) Suggests: spelling, testthat diff --git a/NAMESPACE b/NAMESPACE index 58bc3bc..44e3a43 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ importFrom(beepr,beep) importFrom(dplyr,"%>%") importFrom(dplyr,filter) importFrom(dplyr,mutate) +importFrom(ellipsis,check_dots_used) importFrom(graphics,plot) importFrom(imager,load.image) importFrom(magrittr,"%>%") diff --git a/R/kittyR.R b/R/kittyR.R index dae65bf..0a2cd0f 100644 --- a/R/kittyR.R +++ b/R/kittyR.R @@ -8,6 +8,8 @@ #' \enumerate{ #' \item \url{https://pixabay.com/en/photos/cat/} #' \item \url{https://www.pexels.com/search/cat/} +#' \item \url{https://pixabay.com/en/photos/kitten/} +#' \item \url{https://www.pexels.com/search/kitten/} #' } #' The sound files come from the following CC BY 3.0 source: #' \url{http://soundbible.com/suggest.php?q=cat+meow&x=0&y=0} @@ -17,7 +19,10 @@ #' default collection will be shown. #' @param meow Logical that decides whether to play a meow sound along with the #' picture of a cat. +#' @param only_kitten Logical that decides whether only kitten pics should be +#' selected (default: `FALSE`). #' @inheritParams meowR +#' @param ... Additional arguments (currently ignored). #' #' @importFrom rvest html_session html_nodes html_attr #' @importFrom imager load.image @@ -26,29 +31,53 @@ #' @importFrom dplyr %>% mutate filter #' @importFrom stringr str_split str_remove_all #' @importFrom graphics plot +#' @importFrom ellipsis check_dots_used #' #' @examples #' # relying on default collection -#' set.seed(3444) +#' set.seed(122) #' kittyR::kittyR(meow = FALSE) #' -#' # proving a custom URL +#' # in case you want only pics of kittens +#' set.seed(111) +#' kittyR::kittyR(meow = FALSE, only_kitten = TRUE) +#' +#' # provide a custom URL #' kittyR::kittyR( -#' url = "https://www.pexels.com/search/cat/", +#' url = "https://visualhunt.com/photos/cat/", #' meow = FALSE #' ) #' @export # function body -kittyR <- function(url = NULL, meow = TRUE, sound = 3) { +kittyR <- function(url = NULL, + meow = TRUE, + sound = 3, + only_kitten = FALSE, + ...) { + ellipsis::check_dots_used() + + # if no url is provided if (is.null(url)) { + # if only kitten pics are needed + if (isTRUE(only_kitten)) { + url_list <- list(url = tibble::lst( + "https://pixabay.com/en/photos/kitten/", + "https://www.pexels.com/search/kitten/" + )) + } else { + url_list <- list(url = tibble::lst( + "https://pixabay.com/en/photos/cat/", + "https://www.pexels.com/search/cat/", + "https://pixabay.com/en/photos/kitten/", + "https://www.pexels.com/search/kitten/" + )) + } + # getting the dataframe with image URLs df_combined <- purrr::pmap_dfr( - .l = list(url = tibble::lst( - "https://pixabay.com/en/photos/cat/", - "https://www.pexels.com/search/cat/" - )), + .l = url_list, .f = kittyR::kitty_pics_df, .id = "source" ) @@ -67,7 +96,7 @@ kittyR <- function(url = NULL, meow = TRUE, sound = 3) { ) # bring the kitties to R - kitty <- imager::load.image(temporary_file_location) + kitty <- imager::load.image(file = temporary_file_location) # display the cat graphics::plot(kitty, yaxt = "n", axes = FALSE) @@ -76,5 +105,4 @@ kittyR <- function(url = NULL, meow = TRUE, sound = 3) { if (isTRUE(meow)) { kittyR::meowR(sound = sound) } - } diff --git a/R/kittypics_df_maker.R b/R/kittypics_df_maker.R index 0dff0ae..d7582cf 100644 --- a/R/kittypics_df_maker.R +++ b/R/kittypics_df_maker.R @@ -15,11 +15,14 @@ kitty_pics_df <- function(url) { rvest::html_session(url = url) %>% rvest::html_nodes(x = ., css = "img") + # exclusion pattern + exclude_str_pattern <- "logo|static|users|avatar|assets|hazelnut" + # getting static images df_static <- kitties %>% rvest::html_attr(x = ., name = "src") %>% tibble::enframe(x = ., name = "id", value = "url") %>% - dplyr::filter(.data = ., !stringr::str_detect(url, "static|users|avatar|assets")) + dplyr::filter(.data = ., !stringr::str_detect(url, exclude_str_pattern)) # getting images with two source files (but retaining only the 480 pixel ones) df_srcset <- diff --git a/README.Rmd b/README.Rmd index 87c8151..402be2a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -45,7 +45,7 @@ There are only two available functions in this package- In case you want a picture of a kitty: -```{r kittyR} +```{r kittyR1} # to always have the same kitty on README set.seed(100) @@ -53,11 +53,24 @@ set.seed(100) kittyR::kittyR() ``` +By default, the collection will include any kind of cat (big, small, wild, +etc.). If you want only kittens, you can use an additional argument. + +```{r kittyR2} +# to always have the same kitty on README +set.seed(100) + +# show me the kitten NOW! +kittyR::kittyR(meow = FALSE, only_kitten = TRUE) +``` + The collection of cat pictures comes from the following collections of freely available images: - - + - + - In case you just want to hear a meow either *apropos* nothing or at the end of execution of some code to let you know that the execution is complete, just diff --git a/Rplots.pdf b/Rplots.pdf new file mode 100644 index 0000000..7aa069f Binary files /dev/null and b/Rplots.pdf differ diff --git a/codemeta.json b/codemeta.json index 7f90f6e..7cdc24e 100644 --- a/codemeta.json +++ b/codemeta.json @@ -17,7 +17,7 @@ "version": "3.6.0", "url": "https://r-project.org" }, - "runtimePlatform": "R Under development (unstable) (2019-02-26 r76164)", + "runtimePlatform": "R Under development (unstable) (2019-03-19 r76252)", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -92,7 +92,7 @@ "@type": "SoftwareApplication", "identifier": "dplyr", "name": "dplyr", - "version": ">= 0.7.8", + "version": ">= 0.8.0", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -101,6 +101,18 @@ }, "sameAs": "https://CRAN.R-project.org/package=dplyr" }, + { + "@type": "SoftwareApplication", + "identifier": "ellipsis", + "name": "ellipsis", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=ellipsis" + }, { "@type": "SoftwareApplication", "identifier": "glue", @@ -147,7 +159,7 @@ "@type": "SoftwareApplication", "identifier": "purrr", "name": "purrr", - "version": ">= 0.3.0", + "version": ">= 0.3.2", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -186,7 +198,7 @@ "@type": "SoftwareApplication", "identifier": "tibble", "name": "tibble", - "version": ">= 2.0.1", + "version": ">= 2.1.1", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -196,9 +208,12 @@ "sameAs": "https://CRAN.R-project.org/package=tibble" } ], - "fileSize": "3116.092KB", + "fileSize": "3004.372KB", "contIntegration": [], "developmentStatus": "https://www.tidyverse.org/lifecycle/#experimental", "readme": "https://github.com/IndrajeetPatil/kittyR/blob/master/README.md", - "releaseNotes": "https://github.com/IndrajeetPatil/kittyR/blob/master/NEWS.md" + "releaseNotes": "https://github.com/IndrajeetPatil/kittyR/blob/master/NEWS.md", + "contributor": {}, + "copyrightHolder": {}, + "funder": {} } diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..c111688 --- /dev/null +++ b/docs/404.html @@ -0,0 +1,138 @@ + + + + + + + + +Page not found (404) • kittyR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +Content not found. Please use links in the navbar. + +
+ +
+ + + +
+ + + + + + diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index 9653773..037bd46 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -16,7 +16,8 @@ - + + @@ -78,7 +79,7 @@