Thread: [R-gregmisc-users] SF.net SVN: r-gregmisc:[1451] trunk/gtools/R/mixedsort.R
Brought to you by:
warnes
|
From: <wa...@us...> - 2010-08-14 19:29:01
|
Revision: 1451
http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1451&view=rev
Author: warnes
Date: 2010-08-14 19:28:55 +0000 (Sat, 14 Aug 2010)
Log Message:
-----------
Modify mixedorder()/mixedsort() to better handle strings containing multiple periods, like version numbers (e.g 1.1.2, 1.2.1. 1.1.1.1).
Modified Paths:
--------------
trunk/gtools/R/mixedsort.R
Modified: trunk/gtools/R/mixedsort.R
===================================================================
--- trunk/gtools/R/mixedsort.R 2010-07-23 01:19:16 UTC (rev 1450)
+++ trunk/gtools/R/mixedsort.R 2010-08-14 19:28:55 UTC (rev 1451)
@@ -45,7 +45,7 @@
####
# find and mark numbers in the form of +1.23e+45.67
- delimited <- gsub("([+-]{0,1}[0-9\\.]+([eE][\\+\\-]{0,1}[0-9\\.]+){0,1})",
+ delimited <- gsub("([+-]{0,1}[0-9]+([eE][\\+\\-]{0,1}[0-9]+){0,1})",
paste(delim,"\\1",delim,sep=""), x)
# separate out numbers
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wa...@us...> - 2013-09-23 15:19:09
|
Revision: 1711
http://sourceforge.net/p/r-gregmisc/code/1711
Author: warnes
Date: 2013-09-23 15:19:06 +0000 (Mon, 23 Sep 2013)
Log Message:
-----------
Use 'suppressWarnings() instead of 'options(warn=-1)' in 'mixedorder()'.
Modified Paths:
--------------
trunk/gtools/R/mixedsort.R
Modified: trunk/gtools/R/mixedsort.R
===================================================================
--- trunk/gtools/R/mixedsort.R 2013-07-18 14:09:14 UTC (rev 1710)
+++ trunk/gtools/R/mixedsort.R 2013-09-23 15:19:06 UTC (rev 1711)
@@ -13,19 +13,12 @@
numeric <- function(x)
{
- optwarn = options("warn")
- on.exit( options(optwarn) )
- options(warn=-1)
- as.numeric(x)
+ suppressWarnings( as.numeric(x) )
}
nonnumeric <- function(x)
{
- optwarn = options("warn")
- on.exit( options(optwarn) )
- options(warn=-1)
-
- ifelse(is.na(as.numeric(x)), toupper(x), NA)
+ suppressWarnings( ifelse(is.na(as.numeric(x)), toupper(x), NA) )
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wa...@us...> - 2013-11-06 14:51:18
|
Revision: 1745
http://sourceforge.net/p/r-gregmisc/code/1745
Author: warnes
Date: 2013-11-06 14:51:16 +0000 (Wed, 06 Nov 2013)
Log Message:
-----------
Fix problem with mixedorder/mixedsort when there is only zero or one elements in the vector.
Modified Paths:
--------------
trunk/gtools/R/mixedsort.R
Modified: trunk/gtools/R/mixedsort.R
===================================================================
--- trunk/gtools/R/mixedsort.R 2013-10-21 23:33:29 UTC (rev 1744)
+++ trunk/gtools/R/mixedsort.R 2013-11-06 14:51:16 UTC (rev 1745)
@@ -9,6 +9,11 @@
# - Separately rank numbers and strings
# - Combine orders so that strings follow numbers
+ if(length(x)<1)
+ return(NULL)
+ else if(length(x)==1)
+ return(1)
+
delim="\\$\\@\\$"
numeric <- function(x)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wa...@us...> - 2013-11-26 14:39:04
|
Revision: 1748
http://sourceforge.net/p/r-gregmisc/code/1748
Author: warnes
Date: 2013-11-26 14:38:58 +0000 (Tue, 26 Nov 2013)
Log Message:
-----------
mixedorder() was failing to correctly handle numbers including
decimals due to a faulty regular expression. Prior to the fix:
> drr
[1] "Dose 0.3 mg" "Dose 0.04 mg" "Dose 0.5 mg"
> gtools::mixedsort(drr)
[1] "Dose 0.3 mg" "Dose 0.04 mg" "Dose 0.5 mg"
After the fix:
> drr
[1] "Dose 0.3 mg" "Dose 0.04 mg" "Dose 0.5 mg"
> mixedsort(drr)
[1] "Dose 0.04 mg" "Dose 0.3 mg" "Dose 0.5 mg"
In addition, an optimization was added that checked if the input vector
was numeric. If so, simply use the existing base::order function.
Modified Paths:
--------------
trunk/gtools/R/mixedsort.R
Modified: trunk/gtools/R/mixedsort.R
===================================================================
--- trunk/gtools/R/mixedsort.R 2013-11-18 16:06:26 UTC (rev 1747)
+++ trunk/gtools/R/mixedsort.R 2013-11-26 14:38:58 UTC (rev 1748)
@@ -13,7 +13,11 @@
return(NULL)
else if(length(x)==1)
return(1)
-
+
+ if( is.numeric(x) )
+ return( order(x) )
+
+
delim="\\$\\@\\$"
numeric <- function(x)
@@ -26,16 +30,16 @@
suppressWarnings( ifelse(is.na(as.numeric(x)), toupper(x), NA) )
}
-
x <- as.character(x)
which.nas <- which(is.na(x))
which.blanks <- which(x=="")
if(length(which.blanks) >0)
- x[ which.blanks ] <- -Inf
+ x[ which.blanks ] <- -Inf
+
if(length(which.nas) >0)
- x[ which.nas ] <- Inf
+ x[ which.nas ] <- Inf
####
# - Convert each character string into an vector containing single
@@ -43,7 +47,7 @@
####
# find and mark numbers in the form of +1.23e+45.67
- delimited <- gsub("([+-]{0,1}[0-9]+([eE][\\+\\-]{0,1}[0-9]+){0,1})",
+ delimited <- gsub("([+-]{0,1}[0-9]+.{0,1}[0-9]*([eE][\\+\\-]{0,1}[0-9]+.{0,1}[0-9]*){0,1})",
paste(delim,"\\1",delim,sep=""), x)
# separate out numbers
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <wa...@us...> - 2015-05-02 13:48:38
|
Revision: 2016
http://sourceforge.net/p/r-gregmisc/code/2016
Author: warnes
Date: 2015-05-02 13:48:35 +0000 (Sat, 02 May 2015)
Log Message:
-----------
Remove stray 'svn' that was inserted into the code.
Modified Paths:
--------------
trunk/gtools/R/mixedsort.R
Modified: trunk/gtools/R/mixedsort.R
===================================================================
--- trunk/gtools/R/mixedsort.R 2015-05-02 13:47:47 UTC (rev 2015)
+++ trunk/gtools/R/mixedsort.R 2015-05-02 13:48:35 UTC (rev 2016)
@@ -1,6 +1,6 @@
mixedsort <- function(x, decreasing=FALSE, na.last=TRUE, blank.last=FALSE)
{
- svn ord <- mixedorder(x, decreasing=decreasing, na.last=na.last,
+ ord <- mixedorder(x, decreasing=decreasing, na.last=na.last,
blank.last=blank.last)
x[ord]
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|