boB Rudis
7 years ago
12 changed files with 72 additions and 86 deletions
@ -1,7 +1,11 @@ |
|||||
# Generated by roxygen2: do not edit by hand |
# Generated by roxygen2: do not edit by hand |
||||
|
|
||||
export(bare_combine) |
export(bare_combine) |
||||
export(bare_rename) |
|
||||
export(join_rows) |
export(join_rows) |
||||
|
export(tweet_share) |
||||
|
import(knitr) |
||||
|
import(magick) |
||||
|
import(pdftools) |
||||
|
import(rmarkdown) |
||||
import(rstudioapi) |
import(rstudioapi) |
||||
importFrom(utils,read.csv) |
importFrom(utils,read.csv) |
||||
|
@ -1,43 +0,0 @@ |
|||||
#' Turn a selection of comma-separated bare strings into a dplyr::rename statement |
|
||||
#' |
|
||||
#' Turns \cr\cr |
|
||||
#' \code{a,b c,d,e f}\cr\cr |
|
||||
#' or\cr\cr |
|
||||
#' \code{a, b c, d, e f}\cr\cr |
|
||||
#' into\cr\cr |
|
||||
#' \code{dplyr::rename(a, `b c`, d, `e f`)} |
|
||||
#' |
|
||||
#' @export |
|
||||
bare_rename <- function() { |
|
||||
|
|
||||
ctx <- rstudioapi::getActiveDocumentContext() |
|
||||
|
|
||||
if (!is.null(ctx)) { |
|
||||
|
|
||||
if (ctx$selection[[1]]$text != "") { |
|
||||
|
|
||||
bits <- utils::read.csv(text = ctx$selection[[1]]$text, |
|
||||
stringsAsFactors = FALSE, |
|
||||
header = FALSE) |
|
||||
|
|
||||
bits <- unlist(bits, use.names = FALSE) |
|
||||
|
|
||||
op <- options("useFancyQuotes") |
|
||||
options(useFancyQuotes = FALSE) |
|
||||
|
|
||||
bits <- sapply(bits, trimws) |
|
||||
bits <- ifelse(grepl(" ", bits), dQuote(bits), bits) |
|
||||
bits <- gsub('^"|"$', '`', bits) |
|
||||
|
|
||||
options(op) |
|
||||
|
|
||||
bits <- paste0(bits, collapse = ", ") |
|
||||
bits <- sprintf("dplyr::rename(%s)", bits) |
|
||||
|
|
||||
rstudioapi::modifyRange(ctx$selection[[1]]$range, bits) |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
@ -0,0 +1,39 @@ |
|||||
|
#' Share the active RStudio source tab on Twitter |
||||
|
#' |
||||
|
#' TODO tempdir/tempfile; error checking |
||||
|
#' |
||||
|
#' @export |
||||
|
tweet_share <- function() { |
||||
|
|
||||
|
ctx <- rstudioapi::getSourceEditorContext() |
||||
|
|
||||
|
writeLines(ctx$contents, "/tmp/a.r") |
||||
|
g <- gistr::gist_create("/tmp/a.r", browse=FALSE) |
||||
|
|
||||
|
fil <- file("/tmp/a.rmd", open = "w") |
||||
|
writeLines(c( |
||||
|
"---", |
||||
|
"output: pdf_document", |
||||
|
"---", |
||||
|
"\\pagenumbering{gobble}", |
||||
|
"```{r eval=FALSE}", |
||||
|
ctx$contents, |
||||
|
"```", |
||||
|
sprintf("gist: [%s](%s)", g$url, g$url)), |
||||
|
fil) |
||||
|
close(fil) |
||||
|
|
||||
|
rmarkdown::render("/tmp/a.rmd", rmarkdown::pdf_document(), "/tmp/a.pdf") |
||||
|
|
||||
|
code_raster <- pdftools::pdf_render_page("/tmp/a.pdf", dpi=144) |
||||
|
|
||||
|
img <- magick::image_read(code_raster) |
||||
|
img <- magick::image_trim(img) |
||||
|
|
||||
|
magick::image_write(img, "/tmp/a.png") |
||||
|
|
||||
|
#magick::image_browse(img) |
||||
|
|
||||
|
twitteR::tweet(sprintf("R code: %s", g$url), mediaPath = "/tmp/a.png") |
||||
|
|
||||
|
} |
@ -1,16 +0,0 @@ |
|||||
% Generated by roxygen2: do not edit by hand |
|
||||
% Please edit documentation in R/bare_rename.r |
|
||||
\name{bare_rename} |
|
||||
\alias{bare_rename} |
|
||||
\title{Turn a selection of comma-separated bare strings into a dplyr::rename statement} |
|
||||
\usage{ |
|
||||
bare_rename() |
|
||||
} |
|
||||
\description{ |
|
||||
Turns \cr\cr |
|
||||
\code{a,b c,d,e f}\cr\cr |
|
||||
or\cr\cr |
|
||||
\code{a, b c, d, e f}\cr\cr |
|
||||
into\cr\cr |
|
||||
\code{dplyr::rename(a, `b c`, d, `e f`)} |
|
||||
} |
|
@ -0,0 +1,11 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/tweet-share.r |
||||
|
\name{tweet_share} |
||||
|
\alias{tweet_share} |
||||
|
\title{Share the active RStudio source tab on Twitter} |
||||
|
\usage{ |
||||
|
tweet_share() |
||||
|
} |
||||
|
\description{ |
||||
|
Share the active RStudio source tab on Twitter |
||||
|
} |
Loading…
Reference in new issue