From d3056004b56ab2299d10362b2b495fc24cc5e7bf Mon Sep 17 00:00:00 2001 From: mpadge Date: Fri, 16 Jul 2021 14:03:47 +0200 Subject: [PATCH] separate remove_comments fn for #49 --- DESCRIPTION | 2 +- R/scrape-examples.R | 26 +++++++++++++++++++------- R/text-parsing-fns.R | 7 ------- codemeta.json | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f445abdb..744cad5a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: autotest Title: Automatic Package Testing -Version: 0.0.2.124 +Version: 0.0.2.125 Authors@R: person(given = "Mark", family = "Padgham", diff --git a/R/scrape-examples.R b/R/scrape-examples.R index b7c1c1cc..01664edd 100644 --- a/R/scrape-examples.R +++ b/R/scrape-examples.R @@ -70,6 +70,7 @@ get_fn_exs <- function (package, rd_name, topic, rm_seed = TRUE, if (length (ex) == 0) return (NULL) + ex <- remove_comments (ex) ex <- preprocess_example_lines (ex, exclude_not_run, is_source) if (length (ex) == 0) @@ -225,16 +226,17 @@ get_package_name <- function (package) { return (pkg_name) } -#' A few preprocessing cleaning operations for example code lines +#' Remove comments from code lines #' -#' @param ex Example lines from one '.Rd' file -#' @return Cleaned version of ex +#' Comments are only removed if they are not within quotations. +#' This requires first generating sequences of character indices within +#' quotations. +#' +#' @param ex Examples lines from one .Rd file +#' @return ex with all trailing comments removed #' @noRd -preprocess_example_lines <- function (ex, exclude_not_run, is_source) { +remove_comments <- function (ex) { - # remove comments and empty lines, but only if they are not within - # quotations. This requires first generating sequences of character indices - # within quotations. qts <- gregexpr ("\"|\'", ex) ln_nums <- lapply (seq_along (qts), function (i) rep (i, length (qts [[i]]))) @@ -278,6 +280,16 @@ preprocess_example_lines <- function (ex, exclude_not_run, is_source) { return (ex [i]) }, character (1)) + return (ex) +} + +#' A few preprocessing cleaning operations for example code lines +#' +#' @param ex Example lines from one '.Rd' file +#' @return Cleaned version of ex +#' @noRd +preprocess_example_lines <- function (ex, exclude_not_run, is_source) { + ex <- ex [which (!grepl ("^\\s?$", ex))] # Cut Rd lines down to example code only diff --git a/R/text-parsing-fns.R b/R/text-parsing-fns.R index eaf946a0..807aa541 100644 --- a/R/text-parsing-fns.R +++ b/R/text-parsing-fns.R @@ -12,13 +12,6 @@ match_brackets <- function (x, curly = FALSE) { collapse_sym <- "; " } - # get rid of any comments: - x <- vapply (x, function (i) gsub ("\\#.*", "", i), - character (1), - USE.NAMES = FALSE) - # remove empty lines - x <- x [which (!grepl ("^\\s?$", x))] - brseq <- bracket_sequences (x, open_sym, close_sym, both_sym) br_open <- brseq$br_open br_closed <- brseq$br_closed diff --git a/codemeta.json b/codemeta.json index 9d8b5627..77eaca56 100644 --- a/codemeta.json +++ b/codemeta.json @@ -10,7 +10,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/autotest", "issueTracker": "https://github.com/ropensci-review-tools/autotest/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.0.2.124", + "version": "0.0.2.125", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",