[R-gregmisc-users] SF.net SVN: r-gregmisc:[1914] trunk/gtools
Brought to you by:
warnes
|
From: <wa...@us...> - 2015-04-06 21:40:05
|
Revision: 1914
http://sourceforge.net/p/r-gregmisc/code/1914
Author: warnes
Date: 2015-04-06 21:40:03 +0000 (Mon, 06 Apr 2015)
Log Message:
-----------
- Export S3 methods for first(), last(), left() and right().
- Ensure code matches man page for first(), last(), left(), and right().
Modified Paths:
--------------
trunk/gtools/NAMESPACE
trunk/gtools/R/first.R
Modified: trunk/gtools/NAMESPACE
===================================================================
--- trunk/gtools/NAMESPACE 2015-01-02 20:20:05 UTC (rev 1913)
+++ trunk/gtools/NAMESPACE 2015-04-06 21:40:03 UTC (rev 1914)
@@ -40,3 +40,16 @@
stars.pval,
strmacro
)
+
+S3method(first, default)
+S3method(first, list )
+
+S3method(last, default)
+S3method(last, list )
+
+S3method(left, data.frame)
+S3method(left, matrix)
+
+S3method(right, data.frame)
+S3method(right, matrix)
+
Modified: trunk/gtools/R/first.R
===================================================================
--- trunk/gtools/R/first.R 2015-01-02 20:20:05 UTC (rev 1913)
+++ trunk/gtools/R/first.R 2015-04-06 21:40:03 UTC (rev 1914)
@@ -1,15 +1,18 @@
first <- function(x) UseMethod("first")
last <- function(x) UseMethod("last")
-left <- function(x, n) UseMethod("left")
-right <- function(x, n) UseMethod("left")
+left <- function(x, n=6) UseMethod("left")
+right <- function(x, n=6) UseMethod("left")
+
+
first.default <- function(x) x[1]
last.default <- function(x) x[length(x)]
-first.list <- function(x, ...) x[[1]]
-last.list <- function(x, ...) x[[length(x)]]
+first.list <- function(x) x[[1]]
+last.list <- function(x) x[[length(x)]]
+
left.data.frame <- function(x, n=6)
{
n <- min(n, ncol(x))
@@ -17,6 +20,7 @@
}
left.matrix <- left.data.frame
+
right.data.frame <- function(x, n=6)
{
n <- min(n, ncol(x))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|