@@ -710,7 +710,7 @@ CFVariable <- R6::R6Class("CFVariable",
710710 stop(" The 'time' axis is too short to summarise on." , call. = FALSE ) # nocov
711711 if (is.factor(f )) f <- list (f )
712712
713- tm <- sum( private $ YXZT() > 0L ) # Test which oriented axes are present, T is the last one
713+ tm <- which(names( private $ .axes ) == tax $ name )
714714
715715 # Private group for the result
716716 grp <- CFGroup $ new(" " , NULL )
@@ -1205,6 +1205,8 @@ CFVariable <- R6::R6Class("CFVariable",
12051205 private $ .id <- private $ .NCobj $ id
12061206 } else {
12071207 pack <- private $ .NCobj $ is_packed
1208+ ax_names <- names(private $ .axes )
1209+ scalars <- rep(FALSE , length(ax_names ))
12081210 }
12091211
12101212 # Packing attributes
@@ -1217,7 +1219,7 @@ CFVariable <- R6::R6Class("CFVariable",
12171219
12181220 # Set "coordinates" attribute for scalar axes and labels
12191221 if (any(scalars ) || length(lbls ))
1220- self $ set_attribute(" coordinates" , " NC_CHAR" , paste(c(names( private $ .axes [scalars ]) , lbls ), collapse = " " ))
1222+ self $ set_attribute(" coordinates" , " NC_CHAR" , paste(c(ax_names [scalars ], lbls ), collapse = " " ))
12211223
12221224 private $ write_data(dt , pack = pack , na.mode = 2 )
12231225 private $ .dirty <- FALSE
@@ -1439,6 +1441,8 @@ dimnames.CFVariable <- function(x) {
14391441# ' summer <- pr[, , 173:263]
14401442# ' str(summer)
14411443" [.CFVariable" <- function (x , i , j , ... , drop = FALSE ) {
1444+ caller_env <- parent.frame()
1445+
14421446 numaxes <- x $ ndims
14431447 t <- vector(" list" , numaxes )
14441448 names(t ) <- dimnames(x )[1 : numaxes ]
@@ -1473,7 +1477,7 @@ dimnames.CFVariable <- function(x) {
14731477 if (! is.null(tm )) t [[d ]] <- tm
14741478 } else {
14751479 # Subset the axis
1476- v <- eval(sc [[d ]])
1480+ v <- eval(sc [[d ]], envir = caller_env )
14771481 ex <- range(v )
14781482 start [d ] <- ex [1L ]
14791483 count [d ] <- ex [2L ] - ex [1L ] + 1L
0 commit comments