From c4e4cb29d9dfee1e83312582ddd4138d5d5a347a Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Thu, 7 Mar 2019 16:41:30 -0500 Subject: [PATCH] zap gremlins --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/zap-gremlins.R | 23 +++++++++++++++++++++++ inst/rstudio/addins.dcf | 7 ++++++- man/zapGremlins.Rd | 11 +++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 R/zap-gremlins.R create mode 100644 man/zapGremlins.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 9d7cc8e..b29a268 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,4 +30,4 @@ Imports: dplyr, tidyr, uuid -RoxygenNote: 6.0.1.9000 +RoxygenNote: 6.1.1 diff --git a/NAMESPACE b/NAMESPACE index 52e2a10..b371100 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,7 @@ export(join_rows) export(rantAddin) export(refresh_renviron) export(tweet_share) +export(zapGremlins) import(knitr) import(magick) import(miniUI) diff --git a/R/zap-gremlins.R b/R/zap-gremlins.R new file mode 100644 index 0000000..ef6f150 --- /dev/null +++ b/R/zap-gremlins.R @@ -0,0 +1,23 @@ +#' Find R source files with non-ASCII characters +#' +#' @export +zapGremlins <- function() { + + d <- selectDirectory() + + sapply( + list.files(d, pattern = "[.][Rr]$", full.names = TRUE), + function(.x) { + res <- capture.output(tools::showNonASCIIfile(.x), type = "message") + if (length(res)) { + res <- paste0(c(sprintf("# %s -----------\n", .x), res), collapse="\n") + } + } + ) -> out + + out <- paste0(out, collapse = "\n\n") + + rstudioapi::documentNew(out) + +} + diff --git a/inst/rstudio/addins.dcf b/inst/rstudio/addins.dcf index c976d63..5cd4c16 100644 --- a/inst/rstudio/addins.dcf +++ b/inst/rstudio/addins.dcf @@ -31,4 +31,9 @@ Interactive: false Name: CleanAndGo Description: Cleanse the environment and execute the script Binding: cleanAndGo -Interactive: false \ No newline at end of file +Interactive: false + +Name: Zap Gremlins +Description: Find R source files with non-ASCII characters +Binding: zapGremlins +Interactive: false diff --git a/man/zapGremlins.Rd b/man/zapGremlins.Rd new file mode 100644 index 0000000..98e225c --- /dev/null +++ b/man/zapGremlins.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/zap-gremlins.R +\name{zapGremlins} +\alias{zapGremlins} +\title{Find R source files with non-ASCII characters} +\usage{ +zapGremlins() +} +\description{ +Find R source files with non-ASCII characters +}