Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0dfc862
commit 0117259
Showing
8 changed files
with
126 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
Package: gsubfn | ||
Version: 0.1-1 | ||
Date: 2006-03-24 | ||
Title: gsubfn | ||
Version: 0.1-2 | ||
Date: 2006-04-13 | ||
Title: Like gsub but with replacement function instead of string | ||
Author: G. Grothendieck | ||
Maintainer: Gabor Grothendieck <ggrothendieck@gmail.com> | ||
Description: Miscellaneous string utilities | ||
Depends: R (>= 2.0.0) | ||
License: GPL | ||
Packaged: Tue Apr 4 22:43:22 2006; Kates | ||
Packaged: Mon Apr 17 14:11:49 2006; Grothendieck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
# same as cat except it replaces $x (where x starts with letter and may contain | ||
# letters, numbers and dots) or `x` (where x is any expression not containing | ||
# backticks) with x evaluated and appends \n at end | ||
# The end= argument can be used to append additional characters. | ||
# e.g. cati("letters = $letters, pi = $pi\n") | ||
cati <- | ||
function (..., file = "", sep = " ", fill = FALSE, labels = NULL, | ||
append = FALSE, env = parent.frame(), | ||
pattern = "[$]([[:alpha:]][[:alnum:].]*)|`([^`]+)`", | ||
backref = nchar(base::gsub("[^(]","",pattern)), | ||
end = "") | ||
{ | ||
# added end= argument to cat | ||
cat.end <- | ||
function (..., file = "", sep = " ", fill = FALSE, labels = NULL, | ||
append = FALSE, end = "") | ||
{ | ||
if (is.character(file)) | ||
if (file == "") | ||
file <- stdout() | ||
else if (substring(file, 1, 1) == "|") { | ||
file <- pipe(substring(file, 2), "w") | ||
on.exit(close(file)) | ||
} | ||
else { | ||
file <- file(file, ifelse(append, "a", "w")) | ||
on.exit(close(file)) | ||
} | ||
args <- list(...) | ||
n <- length(args) | ||
args[[n]] <- paste(args[[n]], end, sep = "") | ||
.Internal(cat(args, file, sep, fill, labels, append)) | ||
} | ||
|
||
force(env) | ||
args <- lapply(list(...), function(x) | ||
gsubfn(pattern, , as.character(x), env = env)) | ||
args <- c(args, file = file, sep = sep, fill = fill, labels = labels, | ||
append = append, end = end) | ||
do.call("cat.end", args) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
|
||
0.1-1 Added strapply function, a wrapper for gsubfn. | ||
Changes in 0.1-2 | ||
|
||
o cati added | ||
|
||
o updated DESCRIPTION and gsubfn-package.Rd | ||
|
||
Changes in 0.1-1 | ||
|
||
o strapply added | ||
|
||
o gsubfn-package.Rd added | ||
|
||
Changes in 0.1-0 | ||
|
||
o initial release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
o return matches rather than do a substitution | ||
WISHLIST | ||
|
||
o improve layout of .Rd arg list | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
\name{cati} | ||
\alias{cati} | ||
\title{ cat with string interpolation} | ||
\description{ | ||
Similar to \code{"cat"} except that the strings can include | ||
\code{"gsubfn"}-like string interpolation. | ||
} | ||
\usage{ | ||
cati(..., file = "", sep = " ", fill = FALSE, labels = NULL, append = FALSE, env = parent.frame(), pattern = "[$]([[:alpha:]][[:alnum:].]*)|`([^`]+)`", backref = nchar(base::gsub("[^(]", "", pattern)), end = "") | ||
} | ||
%- maybe also 'usage' for other objects documented here. | ||
\arguments{ | ||
\item{\dots}{ R objects which are coerced to character strings, | ||
concatenated, and printed, with the remaining arguments | ||
controlling the output.} | ||
\item{file}{A connection, or a character string naming the file to print | ||
to. If \code{'""'} (the default), \code{"cat"} prints to the standard | ||
output connection, the console unless redirected by \code{"'sink'"}.} | ||
\item{sep}{character string to insert between the objects to print.} | ||
\item{fill}{ a logical or numeric controlling how the output is broken | ||
into successive lines. If \code{"FALSE"} (default), only newlines | ||
created explicitly by \code{"\\n"} are printed. Otherwise, the | ||
output is broken into lines with print width equal to the | ||
option 'width' if 'fill' is 'TRUE', or the value of 'fill' if | ||
this is numeric.} | ||
\item{labels}{ character vector of labels for the lines printed. Ignored if | ||
'fill' is 'FALSE'.} | ||
\item{append}{logical. Only used if the argument \code{"file"} is the | ||
name of file | ||
(and not a connection or \code{'"|cmd"'}). If \code{"TRUE"} output | ||
will be | ||
appended to \code{"file"}; otherwise, it will overwrite the contents | ||
of \code{"file"}.} | ||
\item{env}{Same as in \code{"gsubfn"}. Normally not used.} | ||
\item{pattern}{Same as in \code{"gsubfn"}. Normally not used.} | ||
\item{backref}{Same as in \code{"gsubfn"}. Normally not used.} | ||
\item{end}{ String to be appended to the output string. \code{"sep"} is | ||
not used to separate \code{"end"}.} | ||
} | ||
\details{ | ||
Similar to \code{"cat"} except that \code{"gsub"}-style string interpolcation | ||
can be used in the arguments. | ||
} | ||
\value{ | ||
None (invisible 'NULL'). | ||
} | ||
\seealso{ Also see \code{\link{gsubfn}}. } | ||
\examples{ | ||
cati("pi = $pi, pi rounded = `round(pi,2)`\\n") | ||
cati(1, 2, 3, sep = ",", end = "\\n") | ||
} | ||
\keyword{character} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters