r-lib / rematch2
Showing 5 of 8 files from the diff.

@@ -5,7 +5,6 @@
Loading
5 5
#' groups from the match of a regular expression to a character vector.
6 6
#' See \code{\link{re_match}}.
7 7
#'
8 -
#' @importFrom tibble tibble new_tibble
9 8
"_PACKAGE"
10 9
11 10
#' Extract Regular Expression Matches Into a Data Frame
@@ -78,6 +77,6 @@
Loading
78 77
  }
79 78
80 79
  names(res) <- c(attr(match, "capture.names"), ".text", ".match")
81 -
  class(res) <- c("tbl_df", "tbl", class(res))
82 -
  res
80 +
81 +
  as_tibble(res)
83 82
}

@@ -2,7 +2,8 @@
Loading
2 2
#'
3 3
#' Taking a data frame and a column name as input, this function will run
4 4
#' \code{\link{re_match}} and bind the results as new columns to the original
5 -
#' table., returning a \code{\link[tibble]{tibble}}. This makes it friendly for
5 +
#' table., returning a \code{\link[tibble]{tibble}} if the tibble package is
6 +
#' installed, a \code{data.frame} otherwise. This makes it friendly for
6 7
#' pipe-oriented programming with \link[magrittr]{magrittr}.
7 8
#'
8 9
#' @note If named capture groups will result in multiple columns with the same
@@ -23,7 +24,8 @@
Loading
23 24
#'   suitable for programming.
24 25
#'
25 26
#' @examples
26 -
#' match_cars <- tibble::rownames_to_column(mtcars)
27 +
#' match_cars <- mtcars
28 +
#' match_cars$rowname <- rownames(mtcars)
27 29
#' bind_re_match(match_cars, rowname, "^(?<make>\\w+) ?(?<model>.+)?$")
28 30
#'
29 31
#' @export
@@ -36,7 +38,9 @@
Loading
36 38
bind_re_match_ <- function(df, from, ..., keep_match = FALSE) {
37 39
38 40
  stopifnot(is.data.frame(df))
39 -
  if (!tibble::has_name(df, from))
41 +
  stopifnot(is_installed("tibble"))
42 +
43 +
  if (!from %in% names(df))
40 44
    stop(from, " is not present in the data frame.")
41 45
42 46
  res <- re_match(text = df[[from]], ...)

@@ -69,12 +69,13 @@
Loading
69 69
    res,
70 70
    names = c(attr(match[[1]], "capture.names"), ".match"),
71 71
    row.names = seq_along(text),
72 -
    class = c("tbl_df", "tbl", "data.frame")
72 +
    class = "data.frame"
73 73
  )
74 74
75 75
  res$.text <- text
76 76
  nc <- ncol(res)
77 -
  res[, c(seq_len(nc - 2), nc, nc - 1)]
77 +
  res <- res[, c(seq_len(nc - 2), nc, nc - 1)]
78 +
  as_tibble(res)
78 79
}
79 80
80 81
match1 <- function(text1, match1) {

@@ -81,10 +81,11 @@
Loading
81 81
    })
82 82
  )
83 83
84 -
  res <- new_tibble(
84 +
  res <- structure(
85 85
    list(text, matchlist),
86 86
    names = c(".text", ".match"),
87 -
    nrow = length(text)
87 +
    row.names = seq_along(text),
88 +
    class = "data.frame"
88 89
  )
89 90
90 91
  if (!is.null(attr(match, "capture.start"))) {
@@ -113,10 +114,11 @@
Loading
113 114
      }
114 115
    )
115 116
116 -
    res <- new_tibble(
117 +
    res <- structure(
117 118
      c(grouplists, res),
118 119
      names = c(attr(match, "capture.names"), ".text", ".match"),
119 -
      nrow = length(res[[1]])
120 +
      row.names = seq_along(text),
121 +
      class = "data.frame"
120 122
    )
121 123
  }
122 124

@@ -0,0 +1,11 @@
Loading
1 +
as_tibble <- function(x) {
2 +
  if (is_installed("tibble")) {
3 +
    tibble::new_tibble(x, nrow = NROW(x))
4 +
  } else {
5 +
    x
6 +
  }
7 +
}
8 +
9 +
is_installed <- function(pkg) {
10 +
  isTRUE(requireNamespace(pkg, quietly = TRUE))
11 +
}
Files Coverage
R 98.91%
Project Totals (8 files) 98.91%
Notifications are pending CI completion. Waiting for GitHub's status webhook to queue notifications. Push notifications now.
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading