diff --git a/DESCRIPTION b/DESCRIPTION index c14af32..637c23b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,5 +25,6 @@ Imports: xslt, clipr, htmltools, - jsonlite + jsonlite, + rstudioapi RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index 672da65..b9962cb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,11 +2,13 @@ S3method(print,hgr) export(clean_text) +export(jtf_addin) export(just_the_facts) import(clipr) import(htmltools) import(httr) import(purrr) +import(rstudioapi) import(xslt) importFrom(jsonlite,fromJSON) importFrom(jsonlite,toJSON) diff --git a/R/aaa.r b/R/aaa.r index d5315ed..dd0ec4f 100644 --- a/R/aaa.r +++ b/R/aaa.r @@ -10,4 +10,15 @@ direction = readr::col_character() ) -.hgr_ua <- "hgr R package / github.com/hrbrmstr/hgr" \ No newline at end of file +.hgr_ua <- "hgr R package / github.com/hrbrmstr/hgr" + +temp_name = function(n = 4, avoid = ls()) { + + tn = paste(sample(letters, n), collapse="") + + while (tn %in% avoid) { + tn = paste(sample(letters, n), collapse="") + } + + tn +} diff --git a/R/hgr-package.R b/R/hgr-package.R index 397a149..a88352f 100644 --- a/R/hgr-package.R +++ b/R/hgr-package.R @@ -11,7 +11,7 @@ #' @import purrr httr clipr htmltools #' @importFrom jsonlite fromJSON toJSON #' @importFrom readr type_convert cols col_character col_datetime -#' @import xslt +#' @import xslt rstudioapi #' @importFrom xml2 read_html #' @importFrom rvest html_text NULL diff --git a/R/jtf_addin.R b/R/jtf_addin.R new file mode 100644 index 0000000..76515fe --- /dev/null +++ b/R/jtf_addin.R @@ -0,0 +1,19 @@ +#' Take URL from clipboard and get the facts! +#' +#' @export +jtf_addin <- function() { + + clip_txt <- trimws(clipr::read_clip())[1] + + if (grepl("^http[s]://", clip_txt)) { + + var_name <- temp_name() + + code_to_exec <- sprintf("print(%s <- hgr::just_the_facts('%s'))", + var_name, clip_txt) + + rstudioapi::sendToConsole(code_to_exec, execute = TRUE) + + } + +} diff --git a/inst/rstudio/addins.dcf b/inst/rstudio/addins.dcf new file mode 100644 index 0000000..29451a0 --- /dev/null +++ b/inst/rstudio/addins.dcf @@ -0,0 +1,5 @@ +Name: Just The Facts +Description: Takes a URL on the clipboard and inserts/executes a call to `just_the_facts()` + that includes "printing" the object which launches a browser with the API call result +Binding: jtf_addin +Interactive: false diff --git a/man/jtf_addin.Rd b/man/jtf_addin.Rd new file mode 100644 index 0000000..6e88e83 --- /dev/null +++ b/man/jtf_addin.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/jtf_addin.R +\name{jtf_addin} +\alias{jtf_addin} +\title{Take URL from clipboard and get the facts!} +\usage{ +jtf_addin() +} +\description{ +Take URL from clipboard and get the facts! +}