Skip to content

Commit

Permalink
separate remove_comments fn for #49
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Jul 16, 2021
1 parent 2681ad2 commit d305600
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
26 changes: 19 additions & 7 deletions R/scrape-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]])))
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions R/text-parsing-fns.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d305600

Please sign in to comment.