├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── CONDUCT.md ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── download_icons.R ├── get_nouns_api.R ├── icons.R ├── make_endpoints.R ├── nounprojectR-package.r ├── np_credentials.R └── ui_addin.R ├── README.md ├── codecov.yml ├── inst └── rstudio │ └── addins.dcf ├── man ├── check_np_response.Rd ├── display_icon.Rd ├── display_many_icons.Rd ├── get_icon_by_term.Rd ├── get_icons_urls.Rd ├── get_nouns_api.Rd ├── get_png.Rd ├── get_pngs_and_show.Rd ├── images │ └── rsaddin.png ├── make_id_endpoint.Rd ├── make_term_endpoint.Rd ├── nounprojectR.Rd └── np_credentials.Rd ├── nounprojectR.Rproj ├── tests ├── testthat.R └── testthat │ ├── .gitignore │ ├── test-download_icons.R │ ├── test-make_endpoints.R │ ├── test-np_oauth.R │ └── test.Rmd └── vignettes └── nounprojectR.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^CONDUCT\.md$ 5 | ^codecov\.yml$ 6 | ^README\.Rmd$ 7 | ^README-.*\.png$ 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | inst/doc 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http:contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: nounprojectR 2 | Title: Explore & view icons from the Noun Project (https://thenounproject.com/) 3 | Version: 0.0.1 4 | Authors@R: c( 5 | person("David", "Parr", email = "first.last@example.com", 6 | role = c("aut", "cre")), 7 | person("Paul", "Brennan", email = "brennanpincardiff@gmail.com", 8 | role = c("ctb")), 9 | person("Dominik", "Krzemiński", email = "raymon92@gmail.com", 10 | role = c("ctb"))) 11 | Description: This package views and downloads icons from the Noun Project (https://thenounproject.com/). It includes a R-Studio AddIn to look at the images. 12 | Depends: R (>= 3.4.0) 13 | License: MIT + file LICENSE 14 | Encoding: UTF-8 15 | LazyData: true 16 | Suggests: covr, testthat, knitr, rmarkdown, 17 | VignetteBuilder: knitr 18 | RoxygenNote: 6.1.0 19 | Imports: magick, 20 | httr, 21 | reticulate, 22 | shiny (>= 0.13), 23 | miniUI (>= 0.1.1), 24 | rstudioapi (>= 0.5) 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2018 2 | COPYRIGHT HOLDER: Your name goes here 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(display_icon) 4 | export(display_many_icons) 5 | export(get_icon_by_term) 6 | export(get_icons_urls) 7 | export(get_nouns_api) 8 | export(get_png) 9 | export(get_pngs_and_show) 10 | export(make_id_endpoint) 11 | export(make_term_endpoint) 12 | export(np_credentials) 13 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # nounprojectR 0.0.0.9000 2 | 3 | * Added a `NEWS.md` file to track changes to the package. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /R/download_icons.R: -------------------------------------------------------------------------------- 1 | #' Get a PNG file after Noun Project access 2 | #' 3 | #' @param res_from_api JSON result from Noun Project API validation 4 | #' 5 | #' @return a PNG pointer that can be shown in the viewer 6 | #' @export 7 | #' 8 | #' @examples 9 | #' # this will show an airplane 10 | #' res <- get_nouns_api("icon/609") 11 | #' get_png(res) 12 | get_png <- function(res_from_api){ 13 | check_np_response(res_from_api) 14 | # PNG can be downloaded using image_read() from magick 15 | png_image <- magick::image_read(httr::content(res_from_api)$icon$preview_url) 16 | return(png_image) 17 | } 18 | 19 | 20 | 21 | #' Download PNG for the icons in a list from get_icon_by_term() 22 | #' 23 | #' @param icon_lists List of details about icons from Noun Project supplied by 24 | #' the function get_icon_by_term() (may be useful for other functions too) 25 | #' 26 | #' @return group of images in a PNG format 27 | #' @export 28 | #' 29 | #' @examples 30 | #' \dontrun{ 31 | #' # assemble the url to get 4 dog icons 32 | #' url <- nounprojectR::make_term_endpoint("dog", num_of_imgs = 4) 33 | #' # obtain information from the Noun Project server 34 | #' res <- get_nouns_api(url) 35 | #' # extract the JSON file 36 | #' result <- httr::content(res) 37 | #' # show the images 38 | #' get_pngs_and_show(result) 39 | #' } 40 | get_pngs_and_show <- function(icon_lists) { 41 | # they all contain PNGs - can be downloaded using image_read() from magick 42 | png_images <- magick::image_read(icon_lists$icons[[1]]$preview_url) 43 | icons <- NULL 44 | for (i in 2:length(icon_lists$icons)) { 45 | icons <- magick::image_read(icon_lists$icons[[i]]$preview_url) 46 | png_images <- c(png_images, icons) 47 | } 48 | return(png_images) 49 | } 50 | -------------------------------------------------------------------------------- /R/get_nouns_api.R: -------------------------------------------------------------------------------- 1 | #' Access Noun Project API with authorisation 2 | #' 3 | #' @param endpoint added information for specific urls on Noun Project API 4 | #' @param baseurl url for the Noun Project API 5 | #' 6 | #' @return JSON object 7 | #' @export 8 | #' 9 | #' @examples 10 | #' \dontrun{No example needed} 11 | get_nouns_api <- function(endpoint, 12 | baseurl = "http://api.thenounproject.com/") { 13 | nouns_app <- httr::oauth_app( 14 | appname = Sys.getenv("NOUNS_API_APPNAME"), 15 | key = Sys.getenv("NOUNS_API_KEY"), 16 | secret = Sys.getenv("NOUNS_API_SECRET") 17 | ) 18 | url <- httr::modify_url(baseurl, path = endpoint) 19 | info <- httr::oauth_signature(url, app = nouns_app) 20 | header_oauth <- httr::oauth_header(info) 21 | httr::GET(url, header_oauth) 22 | } 23 | 24 | 25 | #' Check Noun Project Response 26 | #' 27 | #' @param resp response from np api 28 | #' 29 | #' @examples 30 | #' \dontrun{No example needed} 31 | check_np_response <- function(resp) { 32 | if (httr::status_code(resp) == 403) 33 | stop(paste("NounProject API error - Permission denied.", 34 | "Have you set your credentials using np_credentials() function?")) 35 | if (httr::status_code(resp) != 200) { 36 | stop("NounProject API error - check your query") 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /R/icons.R: -------------------------------------------------------------------------------- 1 | #' Search Noun Project using a Term using Python authentication 2 | #' 3 | #' @param term word for which you would like to search on Noun Project site 4 | #' @param num_of_imgs the number of images you would like to get (default = 4 ) 5 | #' @param limit_to_public_domain enter 0 for NO or 1 for YES (default YES) 6 | #' @param offset how many images would you like to skip (default 0) 7 | #' 8 | #' @return gives a list of image details including urls from which they can be 9 | #' accessed 10 | #' @export 11 | #' 12 | #' @examples 13 | #' \dontrun{ 14 | #' get_icon_by_term("dog") 15 | #' } 16 | get_icon_by_term <- function(term, num_of_imgs=4, limit_to_public_domain=1, offset=0) { 17 | term_ep <- make_term_endpoint(term, limit_to_public_domain, num_of_imgs, offset) 18 | resp <- get_nouns_api(term_ep) 19 | # check response 20 | if (httr::status_code(resp) == 403) 21 | stop(paste("NounProject API error - Permission denied.", 22 | "Have you set your credentials using np_credentials() function?")) 23 | if (httr::status_code(resp) != 200) { 24 | warning("NounProject API error - most likely invalid search term given.") 25 | return(list()) 26 | } 27 | httr::content(resp) 28 | } 29 | 30 | #' Get icons urls 31 | #' 32 | #' @param icon_list list of icons from \code{get_icon_by_term} 33 | #' 34 | #' @return list with field .$url containing url and 35 | #' .$id with icon id as character 36 | #' @export 37 | get_icons_urls <- function(icon_list) { 38 | lapply(icon_list$icons, function(x) list(url=x$preview_url, id=x$id)) 39 | } 40 | 41 | #' Display icon 42 | #' 43 | #' @param icon_number character or string with icon code eg. 13094 44 | #' 45 | #' @return image details and shows image in viewer 46 | #' @export 47 | #' 48 | #' @examples 49 | #' \dontrun{ 50 | #' display_icon(13094) 51 | #' } 52 | display_icon <- function(icon_number) { 53 | icon_number <- as.character(icon_number) 54 | res <- get_nouns_api(paste0("icon/", icon_number)) 55 | get_png(res) 56 | } 57 | 58 | #' Display many icons 59 | #' 60 | #' Displays first num_of_imgs (default 4) icons from The Noun Project. 61 | #' It searches through public domain licensed icons only! 62 | #' 63 | #' @param icon_name character with name of icon to search in nounproject 64 | #' @param num_of_imgs number of images to display (default 4) 65 | #' 66 | #' @return group of images in a PNG format 67 | #' @export 68 | display_many_icons <- function(icon_name, num_of_imgs = 4) { 69 | url <- make_term_endpoint(icon_name, num_of_imgs = num_of_imgs) 70 | res <- get_nouns_api(url) 71 | check_np_response(res) 72 | result <- httr::content(res) 73 | get_pngs_and_show(result) 74 | } 75 | -------------------------------------------------------------------------------- /R/make_endpoints.R: -------------------------------------------------------------------------------- 1 | #' Making the endpoint for searching Noun Project by Term 2 | #' 3 | #' @param term word to use for search 4 | #' @param limit_to_public_domain restrict licence, change to 0 for not limit 5 | #' @param num_of_imgs the number of images required 6 | #' @param offset how many images to ignore, if you want to get different ones 7 | #' 8 | #' @return an url to use with get_nouns_api() 9 | #' @export 10 | #' 11 | #' @examples 12 | #' \dontrun{ 13 | #' # assemble the url to get 4 dog icons 14 | #' url <- nounprojectR::make_term_endpoint("dog", num_of_imgs = 4) 15 | #' # obtain information from the Noun Project server 16 | #' res <- get_nouns_api(url) 17 | #' # extract the JSON file 18 | #' result <- httr::content(res) 19 | #' # show the images 20 | #' get_pngs_and_show(result) 21 | #' } 22 | make_term_endpoint <- function(term, 23 | limit_to_public_domain = 1, 24 | num_of_imgs = 2, 25 | offset = 0) { 26 | term_url <- paste0( 27 | "icons/", 28 | term, 29 | "?limit_to_public_domain=", 30 | limit_to_public_domain, 31 | "&limit=", 32 | num_of_imgs, 33 | "&offset=", 34 | offset 35 | ) 36 | return(term_url) 37 | } 38 | 39 | 40 | #' @title Make the endpoint for an icon url by id 41 | #' @description Accepts id as argument to return partial url 42 | #' @param id numeric id of icon 43 | #' @return partial url string 44 | #' @details pastes 45 | #' @examples 46 | #' \dontrun{ 47 | #' if(interactive()){ 48 | #' #EXAMPLE1 49 | #' } 50 | #' } 51 | #' @rdname make_id_endpoint 52 | #' @export 53 | make_id_endpoint <- function(id){ 54 | id_url <- paste0("/icon/", id) 55 | return(id_url) 56 | } 57 | -------------------------------------------------------------------------------- /R/nounprojectR-package.r: -------------------------------------------------------------------------------- 1 | #' nounprojectR. 2 | #' 3 | #' @name nounprojectR 4 | #' @docType package 5 | NULL 6 | -------------------------------------------------------------------------------- /R/np_credentials.R: -------------------------------------------------------------------------------- 1 | #' Set credentials as system variables 2 | #' 3 | #' @param appname you appname from https://thenounproject.com/developers/apps/ 4 | #' @param key your key from https://thenounproject.com/developers/apps/ 5 | #' @param secret your secret from https://thenounproject.com/developers/apps/ 6 | #' 7 | #' @return invisibly as System Environmental variables: `NOUNS_API_KEY` and `NOUNS_API_SECRET` 8 | #' @export 9 | #' 10 | #' @examples 11 | #' np_credentials("appname", "your-noun-project-key", "your-noun-project-secret") 12 | np_credentials <- function(appname, key, secret) { 13 | Sys.setenv(NOUNS_API_APPNAME = appname) 14 | Sys.setenv(NOUNS_API_KEY = key) 15 | Sys.setenv(NOUNS_API_SECRET = secret) 16 | } 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /R/ui_addin.R: -------------------------------------------------------------------------------- 1 | # Supporting functions 2 | create_image_div <- function(id, url, img_size) { 3 | shiny::div(style = "display:inline-block;margin:5px;", 4 | shiny::tags$img(src = url, width = img_size, height = img_size), 5 | shiny::p(id), 6 | shiny::actionButton(paste0("button",id), "+", style = "margin:1px;") 7 | ) 8 | } 9 | 10 | # Main addin function 11 | nounAddin <- function() { 12 | ui <- miniUI::miniPage( 13 | miniUI::gadgetTitleBar("Noun Project Icons Search"), 14 | miniUI::miniContentPanel( 15 | shiny::div(style = "display:inline-block", 16 | shiny::textInput("search", "What icon do you want to find?")), 17 | shiny::div(style = "display:inline-block", 18 | shiny::actionButton("searchButton", "Search")), 19 | shiny::div(shiny::uiOutput("images"), id = "imagesFrame"), 20 | shiny::div(shiny::p("Selected icons:"), 21 | shiny::verbatimTextOutput("selection", placeholder = TRUE), 22 | shiny::actionButton("clear", "Clear selection")) 23 | ) 24 | ) 25 | 26 | server <- function(input, output, session) { 27 | img_size = "60px" 28 | obs_list <- list() 29 | icons_selection <- c() 30 | 31 | shiny::observeEvent(input$done, { 32 | rstudioapi::sendToConsole( 33 | ifelse(length(icons_selection) > 0, 34 | paste0("c(", 35 | paste(sapply(icons_selection, 36 | function(x) paste0("\"", x, "\"")), 37 | collapse=","), ")"), 38 | ""), 39 | execute = F) 40 | shiny::stopApp() 41 | }) 42 | shiny::observeEvent(input$cancel, { 43 | shiny::stopApp(NULL) 44 | }) 45 | 46 | shiny::observeEvent(input$searchButton, { 47 | imlist <- tryCatch({ 48 | get_icon_by_term(input$search, 20) 49 | }, error = function(e) { 50 | NULL 51 | }) 52 | 53 | imurls <- get_icons_urls(imlist) 54 | 55 | output$images <- shiny::renderUI({ 56 | shiny::validate( 57 | shiny::need(!is.null(imlist), message = paste0("Permission error!\nSet your credentials ", 58 | "using np_credentials() function\n") 59 | ) 60 | ) 61 | shiny::validate( 62 | shiny::need(length(imurls) != 0, message = paste0("A problem with search occured!\n", 63 | "Try searching for a different term.\n") 64 | ) 65 | ) 66 | 67 | lapply(imurls, 68 | function(x) { 69 | btn_name <- paste0("button", x$id) 70 | if (!(btn_name %in% names(obs_list))) 71 | obs_list[[btn_name]] <<- shiny::observeEvent(input[[btn_name]], { 72 | icons_selection <<- c(icons_selection, x$id) 73 | output$selection <- shiny::renderText({ icons_selection }) 74 | shiny::showNotification(paste(x$id, "selected"), duration=2) 75 | }) 76 | create_image_div(x$id, x$url, img_size) 77 | } 78 | ) 79 | }) 80 | }) 81 | shiny::observeEvent(input$clear, { 82 | icons_selection <<- c() 83 | output$selection <- shiny::renderText({ "" }) 84 | }) 85 | } 86 | viewer <- shiny::paneViewer(300) 87 | shiny::runGadget(ui, server, viewer = viewer) 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nounprojectR 2 | 3 | R package to use the [Noun Project](https://thenounproject.com/) API 4 | 5 | [![Build Status](https://travis-ci.org/CaRdiffR/nounprojectR.svg?branch=master)](https://travis-ci.org/CaRdiffR/nounprojectR) 6 | 7 | ### Installation 8 | 9 | ```r 10 | devtools::install_github("CaRdiffR/nounprojectR") 11 | ``` 12 | 13 | ### Basic usage 14 | 15 | To use this package you need to [register with the Noun Project](https://thenounproject.com) and [create an app to get your own key and secret](https://thenounproject.com/developers/apps/). 16 | Copy and paste appname, key and secret and replace in this script: 17 | 18 | ```r 19 | np_credentials(your_appname, your_key, your_secret) 20 | # This function puts the NounProject details into your enviroment variables. 21 | # Equivalent of that would be to set up and export values for the following variables: 22 | # NOUNS_API_APPNAME, NOUNS_API_KEY, NOUNS_API_SECRET 23 | ``` 24 | 25 | To display a single icon that you know the index of, use the `display_icon` function. 26 | 27 | ```r 28 | display_icon("1322") 29 | ``` 30 | 31 | That will open the RStudio Viewer and present you icon number `1322`. 32 | 33 | To display many icons based on your query, use `display_many_icons`: 34 | 35 | ```r 36 | display_many_icons("car") # by default there are 4 icons displayed in loop 37 | 38 | display_many_icons("car", 6) # displays 6 first icons from the nounproject database 39 | ``` 40 | 41 | ### RStudio addin 42 | 43 | Instead of visiting the [Noun Project website](https://thenounproject.com/) all the time, you can use this RStudio addin which will help you to find the icon you are particulalry interested in. By default addin displays 20 most relevant searches for icons with public domain license only. 44 | 45 | TO run it, simply go to `Addins > Noun Project` in your RStudio. 46 | 47 | ![Addin](man/images/rsaddin.png) 48 | 49 | ### Advanced options 50 | 51 | For more advanced usecases, have a look at some examples below. 52 | ```r 53 | # this should download and show the icon of a plane 54 | res <- get_nouns_api("icon/609") 55 | get_png(res) 56 | 57 | # this should download and show the icon of four dogs 58 | # make the url 59 | url <- nounprojectR::make_term_endpoint("dog", num_of_imgs = 4) 60 | # hit the Noun Project server 61 | res <- get_nouns_api(url) 62 | # extract the JSON file 63 | result <- httr::content(res) 64 | # show the images 65 | get_pngs_and_show(result) 66 | ``` 67 | 68 | ### Issues and contributions 69 | Please raise [issues](https://github.com/CaRdiffR/nounprojectR/issues) if you need help or would like to make comments. 70 | 71 | We welcome new contributions! Please read our [Code of Conduct](https://github.com/CaRdiffR/nounprojectR/blob/master/CONDUCT.md) first. 72 | 73 | ### Note 74 | 75 | This project was inspired by the Hacktoberfest 2018. Check out [Hacktoberfest GitHub blog](https://blog.github.com/2018-09-24-hacktoberfest-is-back-and-celebrating-its-fifth-year/) and support the event in the following editions. 76 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | -------------------------------------------------------------------------------- /inst/rstudio/addins.dcf: -------------------------------------------------------------------------------- 1 | Name: Noun Project 2 | Description: This gadget allows you to perform icons search and to select them. 3 | Binding: nounAddin 4 | Interactive: true -------------------------------------------------------------------------------- /man/check_np_response.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_nouns_api.R 3 | \name{check_np_response} 4 | \alias{check_np_response} 5 | \title{Check Noun Project Response} 6 | \usage{ 7 | check_np_response(resp) 8 | } 9 | \arguments{ 10 | \item{resp}{response from np api} 11 | } 12 | \description{ 13 | Check Noun Project Response 14 | } 15 | \examples{ 16 | \dontrun{No example needed} 17 | } 18 | -------------------------------------------------------------------------------- /man/display_icon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/icons.R 3 | \name{display_icon} 4 | \alias{display_icon} 5 | \title{Display icon} 6 | \usage{ 7 | display_icon(icon_number) 8 | } 9 | \arguments{ 10 | \item{icon_number}{character or string with icon code eg. 13094} 11 | } 12 | \value{ 13 | image details and shows image in viewer 14 | } 15 | \description{ 16 | Display icon 17 | } 18 | \examples{ 19 | \dontrun{ 20 | display_icon(13094) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /man/display_many_icons.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/icons.R 3 | \name{display_many_icons} 4 | \alias{display_many_icons} 5 | \title{Display many icons} 6 | \usage{ 7 | display_many_icons(icon_name, num_of_imgs = 4) 8 | } 9 | \arguments{ 10 | \item{icon_name}{character with name of icon to search in nounproject} 11 | 12 | \item{num_of_imgs}{number of images to display (default 4)} 13 | } 14 | \value{ 15 | group of images in a PNG format 16 | } 17 | \description{ 18 | Displays first num_of_imgs (default 4) icons from The Noun Project. 19 | } 20 | -------------------------------------------------------------------------------- /man/get_icon_by_term.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/icons.R 3 | \name{get_icon_by_term} 4 | \alias{get_icon_by_term} 5 | \title{Search Noun Project using a Term using Python authentication} 6 | \usage{ 7 | get_icon_by_term(term, num_of_imgs = 4, limit_to_public_domain = 1, 8 | offset = 0) 9 | } 10 | \arguments{ 11 | \item{term}{word for which you would like to search on Noun Project site} 12 | 13 | \item{num_of_imgs}{the number of images you would like to get (default = 4 )} 14 | 15 | \item{limit_to_public_domain}{enter 0 for NO or 1 for YES (default YES)} 16 | 17 | \item{offset}{how many images would you like to skip (default 0)} 18 | } 19 | \value{ 20 | gives a list of image details including urls from which they can be 21 | accessed 22 | } 23 | \description{ 24 | Search Noun Project using a Term using Python authentication 25 | } 26 | \examples{ 27 | \dontrun{ 28 | get_icon_by_term("dog") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /man/get_icons_urls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/icons.R 3 | \name{get_icons_urls} 4 | \alias{get_icons_urls} 5 | \title{Get icons urls} 6 | \usage{ 7 | get_icons_urls(icon_list) 8 | } 9 | \arguments{ 10 | \item{icon_list}{list of icons from \code{get_icon_by_term}} 11 | } 12 | \value{ 13 | list with field .$url containing url and 14 | .$id with icon id as character 15 | } 16 | \description{ 17 | Get icons urls 18 | } 19 | -------------------------------------------------------------------------------- /man/get_nouns_api.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_nouns_api.R 3 | \name{get_nouns_api} 4 | \alias{get_nouns_api} 5 | \title{Access Noun Project API with authorisation} 6 | \usage{ 7 | get_nouns_api(endpoint, baseurl = "http://api.thenounproject.com/") 8 | } 9 | \arguments{ 10 | \item{endpoint}{added information for specific urls on Noun Project API} 11 | 12 | \item{baseurl}{url for the Noun Project API} 13 | } 14 | \value{ 15 | JSON object 16 | } 17 | \description{ 18 | Access Noun Project API with authorisation 19 | } 20 | \examples{ 21 | 22 | } 23 | -------------------------------------------------------------------------------- /man/get_png.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/download_icons.R 3 | \name{get_png} 4 | \alias{get_png} 5 | \title{Get a PNG file after Noun Project access} 6 | \usage{ 7 | get_png(res_from_api) 8 | } 9 | \arguments{ 10 | \item{res_from_api}{JSON result from Noun Project API validation} 11 | } 12 | \value{ 13 | a PNG pointer that can be shown in the viewer 14 | } 15 | \description{ 16 | Get a PNG file after Noun Project access 17 | } 18 | \examples{ 19 | # this will show an airplane 20 | res <- get_nouns_api("icon/609") 21 | get_png(res) 22 | } 23 | -------------------------------------------------------------------------------- /man/get_pngs_and_show.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/download_icons.R 3 | \name{get_pngs_and_show} 4 | \alias{get_pngs_and_show} 5 | \title{Download PNG for the icons in a list from get_icon_by_term()} 6 | \usage{ 7 | get_pngs_and_show(icon_lists) 8 | } 9 | \arguments{ 10 | \item{icon_lists}{List of details about icons from Noun Project supplied by 11 | the function get_icon_by_term() (may be useful for other functions too)} 12 | } 13 | \value{ 14 | group of images in a PNG format 15 | } 16 | \description{ 17 | Download PNG for the icons in a list from get_icon_by_term() 18 | } 19 | \examples{ 20 | \dontrun{ 21 | # assemble the url to get 4 dog icons 22 | url <- nounprojectR::make_term_endpoint("dog", num_of_imgs = 4) 23 | # obtain information from the Noun Project server 24 | res <- get_nouns_api(url) 25 | # extract the JSON file 26 | result <- httr::content(res) 27 | # show the images 28 | get_pngs_and_show(result) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /man/images/rsaddin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CaRdiffR/nounprojectR/505dee9336fefa00e88e2446225d1ec6c8cb3d8e/man/images/rsaddin.png -------------------------------------------------------------------------------- /man/make_id_endpoint.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_endpoints.R 3 | \name{make_id_endpoint} 4 | \alias{make_id_endpoint} 5 | \title{Make the endpoint for an icon url by id} 6 | \usage{ 7 | make_id_endpoint(id) 8 | } 9 | \arguments{ 10 | \item{id}{numeric id of icon} 11 | } 12 | \value{ 13 | partial url string 14 | } 15 | \description{ 16 | Accepts id as argument to return partial url 17 | } 18 | \details{ 19 | pastes 20 | } 21 | \examples{ 22 | \dontrun{ 23 | if(interactive()){ 24 | #EXAMPLE1 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /man/make_term_endpoint.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make_endpoints.R 3 | \name{make_term_endpoint} 4 | \alias{make_term_endpoint} 5 | \title{Making the endpoint for searching Noun Project by Term} 6 | \usage{ 7 | make_term_endpoint(term, limit_to_public_domain = 1, num_of_imgs = 2, 8 | offset = 0) 9 | } 10 | \arguments{ 11 | \item{term}{word to use for search} 12 | 13 | \item{limit_to_public_domain}{restrict licence, change to 0 for not limit} 14 | 15 | \item{num_of_imgs}{the number of images required} 16 | 17 | \item{offset}{how many images to ignore, if you want to get different ones} 18 | } 19 | \value{ 20 | an url to use with get_nouns_api() 21 | } 22 | \description{ 23 | Making the endpoint for searching Noun Project by Term 24 | } 25 | \examples{ 26 | \dontrun{ 27 | # assemble the url to get 4 dog icons 28 | url <- nounprojectR::make_term_endpoint("dog", num_of_imgs = 4) 29 | # obtain information from the Noun Project server 30 | res <- get_nouns_api(url) 31 | # extract the JSON file 32 | result <- httr::content(res) 33 | # show the images 34 | get_pngs_and_show(result) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /man/nounprojectR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nounprojectR-package.r 3 | \docType{package} 4 | \name{nounprojectR} 5 | \alias{nounprojectR} 6 | \alias{nounprojectR-package} 7 | \title{nounprojectR.} 8 | \description{ 9 | nounprojectR. 10 | } 11 | -------------------------------------------------------------------------------- /man/np_credentials.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/np_credentials.R 3 | \name{np_credentials} 4 | \alias{np_credentials} 5 | \title{Set credentials as system variables} 6 | \usage{ 7 | np_credentials(appname, key, secret) 8 | } 9 | \arguments{ 10 | \item{appname}{you appname from https://thenounproject.com/developers/apps/} 11 | 12 | \item{key}{your key from https://thenounproject.com/developers/apps/} 13 | 14 | \item{secret}{your secret from https://thenounproject.com/developers/apps/} 15 | } 16 | \value{ 17 | invisibly as System Environmental variables: `NOUNS_API_KEY` and `NOUNS_API_SECRET` 18 | } 19 | \description{ 20 | Set credentials as system variables 21 | } 22 | \examples{ 23 | np_credentials("appname", "your-noun-project-key", "your-noun-project-secret") 24 | } 25 | -------------------------------------------------------------------------------- /nounprojectR.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: No 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace 19 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(nounprojectR) 3 | 4 | test_check("nounprojectR") 5 | -------------------------------------------------------------------------------- /tests/testthat/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /tests/testthat/test-download_icons.R: -------------------------------------------------------------------------------- 1 | context("download icons") 2 | 3 | test_that("get icon number 609", { 4 | result <- get_nouns_api("icon/609") 5 | image <- get_png(result) 6 | expect_equal(mode(image), "externalptr") 7 | }) 8 | 9 | test_that("get dogs", { 10 | url <- make_term_endpoint("dog", num_of_imgs = 4) 11 | expect_equal(url, "icons/dog?limit_to_public_domain=1&limit=4&offset=0") 12 | res <- get_nouns_api(url) 13 | expect_equal(length(res), 10) 14 | expect_equal(httr::status_code(res), 200) 15 | result <- httr::content(res) 16 | expect_equal(length(tail(result$icons)), 4) 17 | images <- get_pngs_and_show(result) 18 | expect_equal(mode(images), "externalptr") 19 | expect_equal(length(images), 4) 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-make_endpoints.R: -------------------------------------------------------------------------------- 1 | # unit tests for make_endpoints 2 | context("make_term_endpoint") 3 | test_that("make_term_endpoint",{ 4 | result <- make_term_endpoint("dog") 5 | expect_equal(result, "icons/dog?limit_to_public_domain=1&limit=2&offset=0") 6 | result <- make_term_endpoint("dog", limit_to_public_domain = 0) 7 | expect_equal(result, "icons/dog?limit_to_public_domain=0&limit=2&offset=0") 8 | result <- make_term_endpoint("dog", num_of_imgs = 4) 9 | expect_equal(result, "icons/dog?limit_to_public_domain=1&limit=4&offset=0") 10 | result <- make_term_endpoint("dog", offset = 4) 11 | expect_equal(result, "icons/dog?limit_to_public_domain=1&limit=2&offset=4") 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-np_oauth.R: -------------------------------------------------------------------------------- 1 | context("np_oauth") 2 | 3 | test_that("send a request - no keys", { 4 | # should give error message 5 | result <- httr::GET("http://api.thenounproject.com/icon/1") 6 | expect_equal(httr::status_code(result), 400) 7 | }) 8 | 9 | 10 | test_that("send request - icon number 15", { 11 | result <- get_nouns_api("icon/15") 12 | expect_equal(httr::status_code(result), 200) 13 | expect_equal(mode(httr::content(result)), "list") 14 | expect_equal(length(httr::content(result)), 1) 15 | return <- httr::content(result)$icon 16 | expect_equal(mode(return), "list") 17 | expect_equal(length(return), 23) 18 | expect_equal(return$id, "15") 19 | }) 20 | 21 | test_that("send request - collections", { 22 | result <- get_nouns_api("collections") 23 | expect_equal(httr::status_code(result), 200) 24 | expect_equal(mode(httr::content(result)), "list") 25 | expect_equal(length(httr::content(result)), 1) 26 | return <- httr::content(result)$collections 27 | expect_equal(mode(return), "list") 28 | expect_equal(length(return), 50) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "test" 3 | author: "David Parr" 4 | date: "4 October 2018" 5 | output: html_document 6 | --- 7 | 8 | ```{r setup, include=FALSE} 9 | knitr::opts_chunk$set(echo = TRUE) 10 | ``` 11 | 12 | ## R Markdown 13 | 14 | This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . 15 | 16 | When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: 17 | 18 | ```{r cars} 19 | summary(cars) 20 | ``` 21 | 22 | ## Including Plots 23 | 24 | You can also embed plots, for example: 25 | 26 | ```{r pressure, echo=FALSE} 27 | plot(pressure) 28 | ``` 29 | 30 | Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. 31 | -------------------------------------------------------------------------------- /vignettes/nounprojectR.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Vignette Title" 3 | author: "Vignette Author" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Vignette Title} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | ``` 18 | 19 | Aim of this package so far is to download images from the Noun Project. 20 | 21 | 22 | ## Vignette Info 23 | 24 | Note the various macros within the `vignette` section of the metadata block above. These are required in order to instruct R how to build the vignette. Note that you should change the `title` field and the `\VignetteIndexEntry` to match the title of your vignette. 25 | 26 | ## Styles 27 | 28 | The `html_vignette` template includes a basic CSS theme. To override this theme you can specify your own CSS in the document metadata as follows: 29 | 30 | output: 31 | rmarkdown::html_vignette: 32 | css: mystyles.css 33 | 34 | ## Figures 35 | 36 | The figure sizes have been customised so that you can easily put two images side-by-side. 37 | 38 | ```{r, fig.show='hold'} 39 | plot(1:10) 40 | plot(10:1) 41 | ``` 42 | 43 | You can enable figure captions by `fig_caption: yes` in YAML: 44 | 45 | output: 46 | rmarkdown::html_vignette: 47 | fig_caption: yes 48 | 49 | Then you can use the chunk option `fig.cap = "Your figure caption."` in **knitr**. 50 | 51 | ## More Examples 52 | 53 | You can write math expressions, e.g. $Y = X\beta + \epsilon$, footnotes^[A footnote here.], and tables, e.g. using `knitr::kable()`. 54 | 55 | ```{r, echo=FALSE, results='asis'} 56 | knitr::kable(head(mtcars, 10)) 57 | ``` 58 | 59 | Also a quote using `>`: 60 | 61 | > "He who gives up [code] safety for [code] speed deserves neither." 62 | ([via](https://twitter.com/hadleywickham/status/504368538874703872)) 63 | --------------------------------------------------------------------------------