Skip to content

Commit d7dde15

Browse files
committed
refactor + fix dimnames bug
1 parent c2bad2f commit d7dde15

6 files changed

Lines changed: 10 additions & 62 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: narray
22
Title: R Package for Handling Arrays in a Consistent Manner
3-
Version: 0.1.0
3+
Version: 0.1.1
44
Author: Michael Schubert <mschu.dev@gmail.com>
55
Maintainer: Michael Schubert <mschu.dev@gmail.com>
66
Description: Provides functions to query and manipulate arrays

R/dimnames.r

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
#' @export
1111
dimnames = function(x, along=TRUE, null_as_integer=FALSE, drop=TRUE) {
1212
if (is.list(x) && !is.data.frame(x))
13-
return(lapply(x, dimnames))
13+
return(lapply(x, function(x1) dimnames(x1, along=along,
14+
null_as_integer=null_as_integer, drop=drop)))
1415
if (is.data.frame(x))
1516
x = as.matrix(x)
17+
if (is.vector(x))
18+
x = as.array(x)
1619

1720
dn = base::dimnames(x)
21+
1822
if (is.null(dn))
1923
dn = rep(list(NULL), length(dim(x)))
2024

R/helpers.r renamed to R/match.r

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ match = function(x, from, to, filter_from=NULL, filter_to=NULL, data=parent.fram
5252

5353
# remove identical mappings, then map ambivalent to NA
5454
df = data.frame(from=from, to=to)
55-
df = df[!duplicated(df$from) | rev(duplicated(rev(df$from)))] = NA
55+
df = df[!duplicated(df),]
56+
df[duplicated(df$from) | rev(duplicated(rev(df$from))),] = NA
5657
df = df[!duplicated(df),]
5758
from = df$from
5859
to = df$to
@@ -104,39 +105,3 @@ match = function(x, from, to, filter_from=NULL, filter_to=NULL, data=parent.fram
104105
else
105106
stats::setNames(to, x)
106107
}
107-
108-
#' duplicated() function with extended functionality
109-
#'
110-
#' @param x Object to check for duplicates on
111-
#' @param ... Arguments to be passed to R's `duplicated()`
112-
#' @param all Return all instances of duplicated entries
113-
#' @param random Randomly select with entry is marked as duplicate
114-
duplicated = function(x, ..., all=F, random=F) {
115-
if (all && random)
116-
stop("Can not return all and randomly selected duplicates")
117-
118-
if (all)
119-
base::duplicated(x, ...) | base::duplicated(x, ..., fromLast=TRUE)
120-
else if (random) { # stat.ethz.ch/pipermail/r-help/2010-June/241244.html
121-
if ( is.vector(x) ) {
122-
permutation = sample(length(x))
123-
x.perm = x[permutation]
124-
result.perm = duplicated(x.perm, ...)
125-
result = result.perm[order(permutation)]
126-
return(result)
127-
}
128-
else if ( is.matrix(x) ) {
129-
permutation = sample(nrow(x))
130-
x.perm = x[permutation,]
131-
result.perm = duplicated(x.perm, ...)
132-
result = result.perm[order(permutation)]
133-
return(result)
134-
}
135-
else {
136-
stop(paste("duplicated.random() only supports vectors",
137-
"matrices for now."))
138-
}
139-
}
140-
else
141-
base::duplicated(x, ...)
142-
}

man/duplicated.Rd

Lines changed: 0 additions & 21 deletions
This file was deleted.

man/grapes-or-grapes.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/match.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)