Browse Source

Bare space combine

master
boB Rudis 5 years ago
parent
commit
5d4bec4546
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 4
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 43
      R/bare-space-combine.R
  4. 10
      README.md
  5. 5
      inst/rstudio/addins.dcf
  6. 18
      man/bare_space_combine.Rd

4
DESCRIPTION

@ -1,8 +1,8 @@
Package: hrbraddins
Type: Package
Title: Moar Addins for RStudio
Version: 0.3.0
Date: 2019-07-25
Version: 0.4.0
Date: 2019-07-29
Author: Bob Rudis (bob@rud.is)
Maintainer: Bob Rudis <bob@rud.is>
Description: Provides additional addins for RStudio.

1
NAMESPACE

@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand
export(bare_combine)
export(bare_space_combine)
export(check_package_urls)
export(cleanAndGo)
export(enslave)

43
R/bare-space-combine.R

@ -0,0 +1,43 @@
#' Turn a selection of space-separated bare strings into a base::combine statement
#'
#' Turns \cr\cr
#' \code{a b c d e f}\cr\cr
#' into\cr\cr
#' \code{c("a", "b", "c", "d", "e", "f")}
#'
#' If the option `hrbraddins_uspace` is set TRUE, underscores will be
#' converted to spaces before the final combine statement is created.
#'
#' @export
bare_space_combine <- function() {
ctx <- rstudioapi::getActiveDocumentContext()
if (!is.null(ctx)) {
if (ctx$selection[[1]]$text != "") {
bits <- stri_trim_both(ctx$selection[[1]]$text)
bits <- stri_split_regex(bits, "[[:space:]]+")
bits <- unlist(bits, use.names = FALSE)
qu <- options("useFancyQuotes")
options(useFancyQuotes = FALSE)
uspace <- as.logical(getOption("hrbraddins_uspace", FALSE))
if (uspace) bits <- stri_replace_all_fixed(bits, "_", " ")
bits <- sapply(bits, dQuote)
options(qu)
bits <- paste0(bits, collapse = ", ")
bits <- sprintf("c(%s)", bits)
rstudioapi::modifyRange(ctx$selection[[1]]$range, bits)
}
}
}

10
README.md

@ -30,6 +30,8 @@ The following functions are implemented:
- `bare_combine`: Turn a selection of comma-separated bare strings
into a base::combine statement
- `bare_space_combine`: Turn a selection of space-separated bare
strings into a base::combine statement
- `check_package_urls`: Check package URLs
- `cleanAndGo`: Clean the environment and run the active script
- `enslave`: Run a selection as an RStudio background job
@ -64,10 +66,10 @@ NOTE: To use the ‘remotes’ install options you will need to have the
## hrbraddins Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 14 | 0.93 | 184 | 0.97 | 84 | 0.85 | 79 | 0.77 |
| Rmd | 1 | 0.07 | 5 | 0.03 | 15 | 0.15 | 24 | 0.23 |
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | --: |
| R | 15 | 0.94 | 212 | 0.98 | 97 | 0.87 | 95 | 0.8 |
| Rmd | 1 | 0.06 | 5 | 0.02 | 15 | 0.13 | 24 | 0.2 |
## Code of Conduct

5
inst/rstudio/addins.dcf

@ -13,6 +13,11 @@ Description: Refreshes the in-memory environment variables from ~/.Renviron with
Binding: refresh_renviron
Interactive: false
Name: Bare Space Combine
Description: Turns a selected space-separated list of strings into a base::c() statement
Binding: bare_space_combine
Interactive: false
Name: Bare Combine
Description: Turns a selected comma-separated list of strings into a base::c() statement
Binding: bare_combine

18
man/bare_space_combine.Rd

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bare-space-combine.R
\name{bare_space_combine}
\alias{bare_space_combine}
\title{Turn a selection of space-separated bare strings into a base::combine statement}
\usage{
bare_space_combine()
}
\description{
Turns \cr\cr
\code{a b c d e f}\cr\cr
into\cr\cr
\code{c("a", "b", "c", "d", "e", "f")}
}
\details{
If the option `hrbraddins_uspace` is set TRUE, underscores will be
converted to spaces before the final combine statement is created.
}
Loading…
Cancel
Save