From 2acf1c63de68bc53c28e7ae7fb2bbc5d28919de8 Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Fri, 18 Oct 2019 17:14:35 -0400 Subject: [PATCH] path split --- DESCRIPTION | 1 + NAMESPACE | 2 ++ R/hrbraddins-package.R | 1 + R/path-split.R | 27 +++++++++++++++++++++++++++ inst/rstudio/addins.dcf | 5 +++++ man/pathSplit.Rd | 11 +++++++++++ 6 files changed, 47 insertions(+) create mode 100644 R/path-split.R create mode 100644 man/pathSplit.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 677b575..521ad0f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,6 +28,7 @@ Imports: knitr, twitteR, rtweet, + fs, dplyr, tidyr, uuid, diff --git a/NAMESPACE b/NAMESPACE index 5e54197..15db228 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(check_package_urls) export(cleanAndGo) export(enslave) export(join_rows) +export(pathSplit) export(rantAddin) export(refresh_renviron) export(run_tiny_test) @@ -31,6 +32,7 @@ importFrom(dplyr,full_join) importFrom(dplyr,left_join) importFrom(dplyr,mutate) importFrom(dplyr,progress_estimated) +importFrom(fs,path_split) importFrom(gistr,gist_create) importFrom(httr,GET) importFrom(httr,status_code) diff --git a/R/hrbraddins-package.R b/R/hrbraddins-package.R index 0d87744..1809a97 100644 --- a/R/hrbraddins-package.R +++ b/R/hrbraddins-package.R @@ -17,4 +17,5 @@ #' @importFrom tidyr gather #' @importFrom uuid UUIDgenerate #' @importFrom urltools scheme +#' @importFrom fs path_split "_PACKAGE" diff --git a/R/path-split.R b/R/path-split.R new file mode 100644 index 0000000..82a141a --- /dev/null +++ b/R/path-split.R @@ -0,0 +1,27 @@ +#' Path Split +#' +#' @export +pathSplit <- function() { + + ctx <- rstudioapi::getActiveDocumentContext() + + print(str(ctx$selection)) + + if (!is.null(ctx)) { + + if (ctx$selection[[1]]$text != "") { + + found <- stri_match_first_regex(ctx$selection[[1]]$text, '"([^"]*)"') + + repl <- paste0(sprintf('"%s"', unlist(fs::path_split(found[2]))), collapse = ", ") + + rstudioapi::modifyRange( + ctx$selection[[1]]$range, + stri_replace_first_fixed(ctx$selection[[1]]$text, found[1], repl) + ) + + } + + } + +} diff --git a/inst/rstudio/addins.dcf b/inst/rstudio/addins.dcf index 0c1d9d1..7ddedd2 100644 --- a/inst/rstudio/addins.dcf +++ b/inst/rstudio/addins.dcf @@ -52,3 +52,8 @@ Name: Zap Gremlins Description: Find R source files with non-ASCII characters Binding: zapGremlins Interactive: false + +Name: Path Split +Description: Split a / path to quoted commas +Binding: pathSplit +Interactive: false \ No newline at end of file diff --git a/man/pathSplit.Rd b/man/pathSplit.Rd new file mode 100644 index 0000000..7e80345 --- /dev/null +++ b/man/pathSplit.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/path-split.R +\name{pathSplit} +\alias{pathSplit} +\title{Path Split} +\usage{ +pathSplit() +} +\description{ +Path Split +}