Permalink
Browse files

updated the genX bracketX scrubber arguments

  • Loading branch information...
1 parent ef98f5b commit ab812ea4d1917927951f44ff1ea78bedf43a567e @trinker committed Mar 21, 2013
Showing with 22 additions and 16 deletions.
  1. +8 −9 R/bracketX.R
  2. +6 −2 R/scrubber.R
  3. +4 −4 man/bracketX.Rd
  4. +4 −1 man/scrubber.Rd
View
@@ -10,13 +10,13 @@
#' @param missing Value to assign to empty cells.
#' @param names logical. If TRUE the sentences are given as the names of the
#' counts.
-#' @param space.fix logical. If TRUE extra spaces left behind from an
+#' @param fix.space logical. If TRUE extra spaces left behind from an
#' extraction will be eliminated.
#' @param scrub logical. If TRUE \code{\link[qdap]{scrubber}} will clean the
#' text.
#' @return \code{bracketX} - returns a vector of text with brackets removed.
#' @rdname bracketX
-#' @references \url{http://stackoverflow.com/questions/8621066/remove-text-inside-brackets-parens-and-or-braces}
+#' @references \url{http://stackoverflow.com/q/8621066/1000343}
#' @keywords bracket-remove, parenthesis, bracket, curly-braces
#' @export
#' @seealso
@@ -59,11 +59,10 @@
#' }
bracketX <-
function (text.var, bracket = "all", missing = NULL, names = FALSE,
- space.fix = TRUE, scrub = TRUE) {
+ fix.space = TRUE, scrub = TRUE) {
lside <- rside <- ""
- if (space.fix) {
- lside <- "[ ]*"
- rside <- "[ ]*"
+ if (fix.space) {
+ lside <- rside <- "[ ]*"
}
FUN <- function(bracket, text.var, missing, names) {
X <- switch(bracket,
@@ -80,7 +79,7 @@ function (text.var, bracket = "all", missing = NULL, names = FALSE,
}
)
if (scrub) {
- X <- scrubber(gsub(" +", " ", X))
+ X <- scrubber(gsub(" +", " ", X), fix.space = FALSE)
}
if (!is.null(missing)) {
X[X == ""] <- missing
@@ -167,13 +166,13 @@ function(text.var, bracket = "all", with = FALSE, merge = TRUE){
#' @return \code{genXtract} - returns a vector of text with checks removed.
#' @export
genX <-
-function (text.var, left, right, missing = NULL, names = FALSE, space.fix = TRUE,
+function (text.var, left, right, missing = NULL, names = FALSE, fix.space = TRUE,
scrub = TRUE) {
if (length(left) != length(right)) {
stop("left and right must be equal length")
}
lside <- rside <- ""
- if (space.fix) {
+ if (fix.space) {
lside <- rside <- "[ ]*"
}
specchar <- c(".", "|", "(", ")", "[", "{", "^", "$", "*", "+", "?")
View
@@ -6,6 +6,7 @@
#' @param text.var The text variable.
#' @param num2word logical If TRUE replaces a numbers with text representations.
#' @param fix.comma logical If TRUE removes any spaces before a comma.
+#' @param fix.space logical. If TRUE extra spaces before endmarks are removed.
#' @param rm.quote logical If TRUE removes any \code{\"}.
#' @param \ldots Other arguments passed to \code{\link[qdap]{replace_number}}.
#' @return Returns a parsed character vector.
@@ -19,7 +20,8 @@
#' scrubber(x, TRUE)
#' }
scrubber <-
-function(text.var, num2word = FALSE, rm.quote = TRUE, fix.comma = TRUE, ...){
+function(text.var, num2word = FALSE, rm.quote = TRUE, fix.comma = TRUE,
+ fix.space = TRUE, ...){
x <- reducer(Trim(clean(text.var)))
if (rm.quote) {
x <- gsub('\"', "", x)
@@ -28,7 +30,9 @@ function(text.var, num2word = FALSE, rm.quote = TRUE, fix.comma = TRUE, ...){
x <- gsub(" ,", ",", x)
}
ncx <- nchar(x)
- x <- paste0(Trim(substring(x, 1, ncx - 1)), substring(x, ncx))
+ if (fix.space) {
+ x <- paste0(Trim(substring(x, 1, ncx - 1)), substring(x, ncx))
+ }
x[is.na(text.var)] <- NA
if (num2word) {
x <- replace_number(x, ...)
View
@@ -6,13 +6,13 @@
\title{Bracket Parsing}
\usage{
bracketX(text.var, bracket = "all", missing = NULL,
- names = FALSE, space.fix = TRUE, scrub = TRUE)
+ names = FALSE, fix.space = TRUE, scrub = TRUE)
bracketXtract(text.var, bracket = "all", with = FALSE,
merge = TRUE)
genX(text.var, left, right, missing = NULL,
- names = FALSE, space.fix = TRUE, scrub = TRUE)
+ names = FALSE, fix.space = TRUE, scrub = TRUE)
genXtract(text.var, left, right, with = FALSE,
merge = TRUE)
@@ -31,7 +31,7 @@
\item{names}{logical. If TRUE the sentences are given as
the names of the counts.}
- \item{space.fix}{logical. If TRUE extra spaces left
+ \item{fix.space}{logical. If TRUE extra spaces left
behind from an extraction will be eliminated.}
\item{scrub}{logical. If TRUE
@@ -117,7 +117,7 @@ genX(DATA$state, c("is", "we"), c("too", "on"))
Martin Morgan and Tyler Rinker <tyler.rinker@gmail.com>.
}
\references{
- \url{http://stackoverflow.com/questions/8621066/remove-text-inside-brackets-parens-and-or-braces}
+ \url{http://stackoverflow.com/q/8621066/1000343}
}
\seealso{
\code{\link[base]{regex}}
View
@@ -3,7 +3,7 @@
\title{Clean Imported Text}
\usage{
scrubber(text.var, num2word = FALSE, rm.quote = TRUE,
- fix.comma = TRUE, ...)
+ fix.comma = TRUE, fix.space = TRUE, ...)
}
\arguments{
\item{text.var}{The text variable.}
@@ -14,6 +14,9 @@
\item{fix.comma}{logical If TRUE removes any spaces
before a comma.}
+ \item{fix.space}{logical. If TRUE extra spaces before
+ endmarks are removed.}
+
\item{rm.quote}{logical If TRUE removes any \code{\"}.}
\item{\ldots}{Other arguments passed to

0 comments on commit ab812ea

Please sign in to comment.