Skip to content
This repository
Browse code

updated the genX bracketX scrubber arguments

  • Loading branch information...
commit ab812ea4d1917927951f44ff1ea78bedf43a567e 1 parent ef98f5b
Tyler Rinker authored
17 R/bracketX.R
@@ -10,13 +10,13 @@
10 10 #' @param missing Value to assign to empty cells.
11 11 #' @param names logical. If TRUE the sentences are given as the names of the
12 12 #' counts.
13   -#' @param space.fix logical. If TRUE extra spaces left behind from an
  13 +#' @param fix.space logical. If TRUE extra spaces left behind from an
14 14 #' extraction will be eliminated.
15 15 #' @param scrub logical. If TRUE \code{\link[qdap]{scrubber}} will clean the
16 16 #' text.
17 17 #' @return \code{bracketX} - returns a vector of text with brackets removed.
18 18 #' @rdname bracketX
19   -#' @references \url{http://stackoverflow.com/questions/8621066/remove-text-inside-brackets-parens-and-or-braces}
  19 +#' @references \url{http://stackoverflow.com/q/8621066/1000343}
20 20 #' @keywords bracket-remove, parenthesis, bracket, curly-braces
21 21 #' @export
22 22 #' @seealso
@@ -59,11 +59,10 @@
59 59 #' }
60 60 bracketX <-
61 61 function (text.var, bracket = "all", missing = NULL, names = FALSE,
62   - space.fix = TRUE, scrub = TRUE) {
  62 + fix.space = TRUE, scrub = TRUE) {
63 63 lside <- rside <- ""
64   - if (space.fix) {
65   - lside <- "[ ]*"
66   - rside <- "[ ]*"
  64 + if (fix.space) {
  65 + lside <- rside <- "[ ]*"
67 66 }
68 67 FUN <- function(bracket, text.var, missing, names) {
69 68 X <- switch(bracket,
@@ -80,7 +79,7 @@ function (text.var, bracket = "all", missing = NULL, names = FALSE,
80 79 }
81 80 )
82 81 if (scrub) {
83   - X <- scrubber(gsub(" +", " ", X))
  82 + X <- scrubber(gsub(" +", " ", X), fix.space = FALSE)
84 83 }
85 84 if (!is.null(missing)) {
86 85 X[X == ""] <- missing
@@ -167,13 +166,13 @@ function(text.var, bracket = "all", with = FALSE, merge = TRUE){
167 166 #' @return \code{genXtract} - returns a vector of text with checks removed.
168 167 #' @export
169 168 genX <-
170   -function (text.var, left, right, missing = NULL, names = FALSE, space.fix = TRUE,
  169 +function (text.var, left, right, missing = NULL, names = FALSE, fix.space = TRUE,
171 170 scrub = TRUE) {
172 171 if (length(left) != length(right)) {
173 172 stop("left and right must be equal length")
174 173 }
175 174 lside <- rside <- ""
176   - if (space.fix) {
  175 + if (fix.space) {
177 176 lside <- rside <- "[ ]*"
178 177 }
179 178 specchar <- c(".", "|", "(", ")", "[", "{", "^", "$", "*", "+", "?")
8 R/scrubber.R
@@ -6,6 +6,7 @@
6 6 #' @param text.var The text variable.
7 7 #' @param num2word logical If TRUE replaces a numbers with text representations.
8 8 #' @param fix.comma logical If TRUE removes any spaces before a comma.
  9 +#' @param fix.space logical. If TRUE extra spaces before endmarks are removed.
9 10 #' @param rm.quote logical If TRUE removes any \code{\"}.
10 11 #' @param \ldots Other arguments passed to \code{\link[qdap]{replace_number}}.
11 12 #' @return Returns a parsed character vector.
@@ -19,7 +20,8 @@
19 20 #' scrubber(x, TRUE)
20 21 #' }
21 22 scrubber <-
22   -function(text.var, num2word = FALSE, rm.quote = TRUE, fix.comma = TRUE, ...){
  23 +function(text.var, num2word = FALSE, rm.quote = TRUE, fix.comma = TRUE,
  24 + fix.space = TRUE, ...){
23 25 x <- reducer(Trim(clean(text.var)))
24 26 if (rm.quote) {
25 27 x <- gsub('\"', "", x)
@@ -28,7 +30,9 @@ function(text.var, num2word = FALSE, rm.quote = TRUE, fix.comma = TRUE, ...){
28 30 x <- gsub(" ,", ",", x)
29 31 }
30 32 ncx <- nchar(x)
31   - x <- paste0(Trim(substring(x, 1, ncx - 1)), substring(x, ncx))
  33 + if (fix.space) {
  34 + x <- paste0(Trim(substring(x, 1, ncx - 1)), substring(x, ncx))
  35 + }
32 36 x[is.na(text.var)] <- NA
33 37 if (num2word) {
34 38 x <- replace_number(x, ...)
8 man/bracketX.Rd
@@ -6,13 +6,13 @@
6 6 \title{Bracket Parsing}
7 7 \usage{
8 8 bracketX(text.var, bracket = "all", missing = NULL,
9   - names = FALSE, space.fix = TRUE, scrub = TRUE)
  9 + names = FALSE, fix.space = TRUE, scrub = TRUE)
10 10
11 11 bracketXtract(text.var, bracket = "all", with = FALSE,
12 12 merge = TRUE)
13 13
14 14 genX(text.var, left, right, missing = NULL,
15   - names = FALSE, space.fix = TRUE, scrub = TRUE)
  15 + names = FALSE, fix.space = TRUE, scrub = TRUE)
16 16
17 17 genXtract(text.var, left, right, with = FALSE,
18 18 merge = TRUE)
@@ -31,7 +31,7 @@
31 31 \item{names}{logical. If TRUE the sentences are given as
32 32 the names of the counts.}
33 33
34   - \item{space.fix}{logical. If TRUE extra spaces left
  34 + \item{fix.space}{logical. If TRUE extra spaces left
35 35 behind from an extraction will be eliminated.}
36 36
37 37 \item{scrub}{logical. If TRUE
@@ -117,7 +117,7 @@ genX(DATA$state, c("is", "we"), c("too", "on"))
117 117 Martin Morgan and Tyler Rinker <tyler.rinker@gmail.com>.
118 118 }
119 119 \references{
120   - \url{http://stackoverflow.com/questions/8621066/remove-text-inside-brackets-parens-and-or-braces}
  120 + \url{http://stackoverflow.com/q/8621066/1000343}
121 121 }
122 122 \seealso{
123 123 \code{\link[base]{regex}}
5 man/scrubber.Rd
@@ -3,7 +3,7 @@
3 3 \title{Clean Imported Text}
4 4 \usage{
5 5 scrubber(text.var, num2word = FALSE, rm.quote = TRUE,
6   - fix.comma = TRUE, ...)
  6 + fix.comma = TRUE, fix.space = TRUE, ...)
7 7 }
8 8 \arguments{
9 9 \item{text.var}{The text variable.}
@@ -14,6 +14,9 @@
14 14 \item{fix.comma}{logical If TRUE removes any spaces
15 15 before a comma.}
16 16
  17 + \item{fix.space}{logical. If TRUE extra spaces before
  18 + endmarks are removed.}
  19 +
17 20 \item{rm.quote}{logical If TRUE removes any \code{\"}.}
18 21
19 22 \item{\ldots}{Other arguments passed to

0 comments on commit ab812ea

Please sign in to comment.
Something went wrong with that request. Please try again.