commit 388867506106a6f779ab3c2bde3a0ed0ed9861f6 Author: boB Rudis Date: Sun Mar 12 09:18:38 2017 -0400 initial commit diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..9cb436b --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,11 @@ +^.*\.Rproj$ +^\.Rproj\.user$ +^\.travis\.yml$ +^README\.*Rmd$ +^README\.*html$ +^NOTES\.*Rmd$ +^NOTES\.*html$ +^\.codecov\.yml$ +^README_files$ +^doc$ +^codecov\.yml$ diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..69cb760 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1 @@ +comment: false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cce1f17 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +.Rproj.user +.Rhistory +.RData +.Rproj +src/*.o +src/*.so +src/*.dll diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..50534d1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: R +sudo: false +cache: packages + +after_success: + - Rscript -e 'covr::codecov()' \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..81da0c5 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,19 @@ +Package: hrbraddins +Type: Package +Title: Additional Addins for RStudio +Version: 0.1.0 +Date: 2017-03-12 +Author: Bob Rudis (bob@rud.is) +Maintainer: Bob Rudis +Description: Provides additional addins for RStudio. +URL: https://github.com/hrbrmstr/hrbraddins +BugReports: https://github.com/hrbrmstr/hrbraddins/issues +License: MIT + file LICENSE +Suggests: testthat, + covr +Depends: + R (>= 3.2.0) +Imports: + rstudioapi (>= 0.4), + utils +RoxygenNote: 6.0.1 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..48ed424 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2017 +COPYRIGHT HOLDER: Bob Rudis diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..c9cabb7 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,7 @@ +# Generated by roxygen2: do not edit by hand + +export(bare_combine) +export(bare_rename) +export(join_rows) +import(rstudioapi) +importFrom(utils,read.csv) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..9b4679b --- /dev/null +++ b/NEWS.md @@ -0,0 +1,2 @@ +0.1.0 +* Initial release diff --git a/R/bare_combine.r b/R/bare_combine.r new file mode 100644 index 0000000..42905c0 --- /dev/null +++ b/R/bare_combine.r @@ -0,0 +1,42 @@ +#' Turn a selection of comma-separated bare strings into a base::combine 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{c("a", "b c", "d", "e f")} +#' +#' @export +bare_combine <- 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 <- sapply(bits, dQuote) + + options(op) + + bits <- paste0(bits, collapse = ", ") + bits <- sprintf("c(%s)", bits) + + rstudioapi::modifyRange(ctx$selection[[1]]$range, bits) + + } + + } + +} diff --git a/R/bare_rename.r b/R/bare_rename.r new file mode 100644 index 0000000..6a6cd00 --- /dev/null +++ b/R/bare_rename.r @@ -0,0 +1,43 @@ +#' 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) + + } + + } + +} diff --git a/R/hrbraddins-package.R b/R/hrbraddins-package.R new file mode 100644 index 0000000..200c366 --- /dev/null +++ b/R/hrbraddins-package.R @@ -0,0 +1,8 @@ +#' Additional Addins for RStudio +#' +#' @name hrbraddins +#' @docType package +#' @author Bob Rudis (bob@@rud.is) +#' @import rstudioapi +#' @importFrom utils read.csv +NULL diff --git a/R/join_rows.r b/R/join_rows.r new file mode 100644 index 0000000..a4fa576 --- /dev/null +++ b/R/join_rows.r @@ -0,0 +1,32 @@ +#' Join cr/lf-separated selected rows of text into a single space-separated row +#' +#' Turns +#' \preformatted{ +#' a +#' b +#' c +#' d +#' } +#' into\cr\cr +#' \code{a b c d} +#' +#' @export +join_rows <- function() { + + ctx <- rstudioapi::getActiveDocumentContext() + + if (!is.null(ctx)) { + + if (ctx$selection[[1]]$text != "") { + + bits <- ctx$selection[[1]]$text + bits <- gsub("[\r\n]+", " ", bits) + bits <- paste0(bits, collapse="") + + rstudioapi::modifyRange(ctx$selection[[1]]$range, bits) + + } + + } + +} diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..a1947c7 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,62 @@ +--- +output: rmarkdown::github_document +--- +[![Travis-CI Build Status](https://travis-ci.org/.svg?branch=master)](https://travis-ci.org/) +[![Coverage Status](https://img.shields.io/codecov/c/github//master.svg)](https://codecov.io/github/?branch=master) + +`hrbraddins` : Additional Addins for RStudio + +The following functions are implemented: + +- `bare_combine`: Turn a selection of comma-separated bare strings into a - `base::combine`: statement +- `bare_rename`: Turn a selection of comma-separated bare strings into a `dplyr::rename` statement + +### More Info + +The RStudio Addins menu selection "Bare Rename" will take a text selection and make it into `dplyr::rename()` statement For example: + + a,b c,d,e f + +or + + a, b c, d, e f + +will be converted to: + + dplyr::rename(a, `b c`, d, `e f`) + +**NOTE**: not all backtick-edge cases are handled (yet). + +Similarly, the RStudio Addins menu selection "Bare Combine" will take a text selection and make it into a `c()` statement. For example: + + a,b c,d,e f + +or + + a, b c, d, e f + +will be converted to: + + c("a", "b c", "d", "e f") + +**NOTE**: not all double-quote edge cases are handled (yet). + +Finally, unless I'm missing something, RStudio doesn't have a "join rows" option, so you can use the RStudio Addins menu selection "Join Rows" to do just that. So: + + a + b + c + d + +becomes: + + a b c d + +The best way to find out if I'm wrong about that is by doing this tho since the internet will gladly tell me if I'm wrong. + +### Installation + +```{r eval=FALSE} +devtools::install_github("hrbrmstr/hrbraddins") +``` + diff --git a/README.md b/README.md new file mode 100644 index 0000000..22f97ec --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ + +[![Travis-CI Build Status](https://travis-ci.org/.svg?branch=master)](https://travis-ci.org/) [![Coverage Status](https://img.shields.io/codecov/c/github//master.svg)](https://codecov.io/github/?branch=master) + +`hrbraddins` : Additional Addins for RStudio + +The following functions are implemented: + +- `bare_combine`: Turn a selection of comma-separated bare strings into a - `base::combine`: statement +- `bare_rename`: Turn a selection of comma-separated bare strings into a `dplyr::rename` statement + +### More Info + +The RStudio Addins menu selection "Bare Rename" will take a text selection and make it into `dplyr::rename()` statement For example: + + a,b c,d,e f + +or + + a, b c, d, e f + +will be converted to: + + dplyr::rename(a, `b c`, d, `e f`) + +**NOTE**: not all backtick-edge cases are handled (yet). + +Similarly, the RStudio Addins menu selection "Bare Combine" will take a text selection and make it into a `c()` statement. For example: + + a,b c,d,e f + +or + + a, b c, d, e f + +will be converted to: + + c("a", "b c", "d", "e f") + +**NOTE**: not all double-quote edge cases are handled (yet). + +Finally, unless I'm missing something, RStudio doesn't have a "join rows" option, so you can use the RStudio Addins menu selection "Join Rows" to do just that. So: + + a + b + c + d + +becomes: + + a b c d + +The best way to find out if I'm wrong about that is by doing this tho since the internet will gladly tell me if I'm wrong. + +### Installation + +``` r +devtools::install_github("hrbrmstr/hrbraddins") +``` diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..69cb760 --- /dev/null +++ b/codecov.yml @@ -0,0 +1 @@ +comment: false diff --git a/hrbraddins.Rproj b/hrbraddins.Rproj new file mode 100644 index 0000000..446d9e1 --- /dev/null +++ b/hrbraddins.Rproj @@ -0,0 +1,21 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +StripTrailingWhitespace: Yes + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageBuildArgs: --resave-data +PackageRoxygenize: rd,collate,namespace diff --git a/inst/rstudio/addins.dcf b/inst/rstudio/addins.dcf new file mode 100644 index 0000000..a9e72fb --- /dev/null +++ b/inst/rstudio/addins.dcf @@ -0,0 +1,14 @@ +Name: Bare Rename +Description: Turns a selected comma-separated list of strings into a dplyr::rename() statement +Binding: bare_rename +Interactive: false + +Name: Bare Combine +Description: Turns a selected comma-separated list of strings into a base::c() statement +Binding: bare_combine +Interactive: false + +Name: Join Rows +Description: Join a selected set of rows into one line +Binding: join_rows +Interactive: false \ No newline at end of file diff --git a/man/bare_combine.Rd b/man/bare_combine.Rd new file mode 100644 index 0000000..d1385a0 --- /dev/null +++ b/man/bare_combine.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bare_combine.r +\name{bare_combine} +\alias{bare_combine} +\title{Turn a selection of comma-separated bare strings into a base::combine statement} +\usage{ +bare_combine() +} +\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{c("a", "b c", "d", "e f")} +} diff --git a/man/bare_rename.Rd b/man/bare_rename.Rd new file mode 100644 index 0000000..36def8f --- /dev/null +++ b/man/bare_rename.Rd @@ -0,0 +1,16 @@ +% 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`)} +} diff --git a/man/hrbraddins.Rd b/man/hrbraddins.Rd new file mode 100644 index 0000000..0bf06f1 --- /dev/null +++ b/man/hrbraddins.Rd @@ -0,0 +1,13 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hrbraddins-package.R +\docType{package} +\name{hrbraddins} +\alias{hrbraddins} +\alias{hrbraddins-package} +\title{Additional Addins for RStudio} +\description{ +Additional Addins for RStudio +} +\author{ +Bob Rudis (bob@rud.is) +} diff --git a/man/join_rows.Rd b/man/join_rows.Rd new file mode 100644 index 0000000..89ac6f8 --- /dev/null +++ b/man/join_rows.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/join_rows.r +\name{join_rows} +\alias{join_rows} +\title{Join cr/lf-separated selected rows of text into a single space-separated row} +\usage{ +join_rows() +} +\description{ +Turns +\preformatted{ +a +b +c +d +} +into\cr\cr +\code{a b c d} +} diff --git a/tests/test-all.R b/tests/test-all.R new file mode 100644 index 0000000..530b15b --- /dev/null +++ b/tests/test-all.R @@ -0,0 +1,2 @@ +library(testthat) +test_check("hrbraddins") diff --git a/tests/testthat/test-hrbraddins.R b/tests/testthat/test-hrbraddins.R new file mode 100644 index 0000000..6e4fb72 --- /dev/null +++ b/tests/testthat/test-hrbraddins.R @@ -0,0 +1,8 @@ +context("basic functionality") +test_that("we can do something", { + + expect_error(bare_combine()) + expect_error(bare_rename()) + expect_error(join_rows()) + +})