Permalink
Browse files

Correct logic for choosing type of subscripting

  • Loading branch information...
1 parent 31e8102 commit efabba6ab5cf870a47b7ee1b3093ab60949a0065 @hadley committed Apr 11, 2009
Showing with 19 additions and 3 deletions.
  1. +19 −3 R/indexed-array.r
View
@@ -8,10 +8,26 @@
# @alias names.indexed_array
# @alias length.indexed_array
indexed_array <- function(env, index) {
- if (is.list(env$data) && !is.data.frame(env$data)) { # && !is.array(data)
- subs <- c("[[", "]]")
+ exact <- all(laply(index, is.numeric))
+
+ # Situations that should use [
+ # * data.frame
+ # * normal array
+ # * normal vector
+ # * list-array with inexact indexing
+ #
+ # Situations that should use [[
+ # * list
+ # * list-array with exact indexing
+
+ if (is.list(env$data)) {
+ if (is.data.frame(env$data) || (is.array(env$data) && !exact)) {
+ subs <- c("[", "]")
+ } else {
+ subs <- c("[[", "]]")
+ }
} else {
- subs <- c("[", "]")
+ subs <- c("[", "]")
}
structure(

0 comments on commit efabba6

Please sign in to comment.