commit
3888675061
23 changed files with 411 additions and 0 deletions
@ -0,0 +1,11 @@ |
|||
^.*\.Rproj$ |
|||
^\.Rproj\.user$ |
|||
^\.travis\.yml$ |
|||
^README\.*Rmd$ |
|||
^README\.*html$ |
|||
^NOTES\.*Rmd$ |
|||
^NOTES\.*html$ |
|||
^\.codecov\.yml$ |
|||
^README_files$ |
|||
^doc$ |
|||
^codecov\.yml$ |
@ -0,0 +1 @@ |
|||
comment: false |
@ -0,0 +1,8 @@ |
|||
.DS_Store |
|||
.Rproj.user |
|||
.Rhistory |
|||
.RData |
|||
.Rproj |
|||
src/*.o |
|||
src/*.so |
|||
src/*.dll |
@ -0,0 +1,6 @@ |
|||
language: R |
|||
sudo: false |
|||
cache: packages |
|||
|
|||
after_success: |
|||
- Rscript -e 'covr::codecov()' |
@ -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 <bob@rud.is> |
|||
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 |
@ -0,0 +1,2 @@ |
|||
YEAR: 2017 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -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) |
@ -0,0 +1,2 @@ |
|||
0.1.0 |
|||
* Initial release |
@ -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) |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
@ -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) |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
@ -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 |
@ -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) |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,62 @@ |
|||
--- |
|||
output: rmarkdown::github_document |
|||
--- |
|||
[](https://travis-ci.org/) |
|||
[](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") |
|||
``` |
|||
|
@ -0,0 +1,58 @@ |
|||
|
|||
[](https://travis-ci.org/) [](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") |
|||
``` |
@ -0,0 +1 @@ |
|||
comment: false |
@ -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 |
@ -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 |
@ -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")} |
|||
} |
@ -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`)} |
|||
} |
@ -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) |
|||
} |
@ -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} |
|||
} |
@ -0,0 +1,2 @@ |
|||
library(testthat) |
|||
test_check("hrbraddins") |
@ -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()) |
|||
|
|||
}) |
Loading…
Reference in new issue