[R-gregmisc-commits] r2047 - pkg/gtools/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed May 27 18:36:14 CEST 2015
Author: warnes
Date: 2015-05-27 18:36:13 +0200 (Wed, 27 May 2015)
New Revision: 2047
Added:
pkg/gtools/R/trimws.R
Removed:
pkg/gtools/R/trim.R
Modified:
pkg/gtools/R/keywords.R
pkg/gtools/R/roman2int.R
Log:
Two functions in gtools need to use either gdata::trim() or
base::trimws() (added in R 3.2.0). The previous solution was to
include gdata/R/gdata/R/trim.R in gtools using a symbolic link.
Unfortunately, Rforge doesn't seem to like the symbolic link when
building packages, and generates an error.
So, instead, create the file trimws.R, which creates trimws() if it
isn't already available (e.g. via base::trimws), and modify keywords()
and roman2int() to use trimws() instead of gdata::trim().
Modified: pkg/gtools/R/keywords.R
===================================================================
--- pkg/gtools/R/keywords.R 2015-05-27 02:48:54 UTC (rev 2046)
+++ pkg/gtools/R/keywords.R 2015-05-27 16:36:13 UTC (rev 2047)
@@ -8,20 +8,11 @@
}
else
{
-
- ## Local copy of trim.character to avoid cyclic dependency with gdata ##
- trim <- function(s)
- {
- s <- sub(pattern="^[[:blank:]]+", replacement="", x=s)
- s <- sub(pattern="[[:blank:]]+$", replacement="", x=s)
- s
- }
-
kw <- scan(file=file, what=character(), sep="\n", quiet=TRUE)
kw <- grep("&", kw, value=TRUE)
kw <- gsub("&[^&]*$","", kw)
kw <- gsub("&+"," ", kw)
- kw <- na.omit(trim(kw))
+ kw <- na.omit(trimws(kw))
ischar <- tryCatch(is.character(topic) && length(topic) ==
1L, error = identity)
Modified: pkg/gtools/R/roman2int.R
===================================================================
--- pkg/gtools/R/roman2int.R 2015-05-27 02:48:54 UTC (rev 2046)
+++ pkg/gtools/R/roman2int.R 2015-05-27 16:36:13 UTC (rev 2047)
@@ -30,7 +30,7 @@
roman2int <- function(roman)
{
- roman <- trim(toupper(as.character(roman)))
+ roman <- trimws(toupper(as.character(roman)))
tryIt <- function(x)
{
Deleted: pkg/gtools/R/trim.R
===================================================================
--- pkg/gtools/R/trim.R 2015-05-27 02:48:54 UTC (rev 2046)
+++ pkg/gtools/R/trim.R 2015-05-27 16:36:13 UTC (rev 2047)
@@ -1 +0,0 @@
-link ../../gdata/R/trim.R
\ No newline at end of file
Added: pkg/gtools/R/trimws.R
===================================================================
--- pkg/gtools/R/trimws.R (rev 0)
+++ pkg/gtools/R/trimws.R 2015-05-27 16:36:13 UTC (rev 2047)
@@ -0,0 +1,11 @@
+## trimws was added in R 2.3.0. If we're using a previous version of
+## R we need to define it.
+if(!exists('trimws', mode='function')
+ trimws <- function(s)
+ {
+ s <- sub(pattern="^[[:blank:]]+", replacement="", x=s)
+ s <- sub(pattern="[[:blank:]]+$", replacement="", x=s)
+ s
+ }
+
+
More information about the R-gregmisc-commits
mailing list