Fixed handling of empty x argument

This commit is contained in:
Waldir Leoncio 2020-01-30 17:31:25 +01:00
parent 1ac54301a6
commit c9c9b7cb26
2 changed files with 9 additions and 0 deletions

View file

@ -17,6 +17,7 @@ export(repmat)
export(simulateAllFreqs) export(simulateAllFreqs)
export(simulateIndividuals) export(simulateIndividuals)
export(simuloiAlleeli) export(simuloiAlleeli)
export(size)
export(suoritaMuutos) export(suoritaMuutos)
export(times) export(times)
importFrom(stats,runif) importFrom(stats,runif)

View file

@ -7,8 +7,16 @@
#' default behavior is more reasonable in those cases (i.e., returning NA), #' default behavior is more reasonable in those cases (i.e., returning NA),
#' but since the point of this function is to replicate MATLAB behaviors #' but since the point of this function is to replicate MATLAB behaviors
#' (bugs and questionable behaviors included), this function also does this. #' (bugs and questionable behaviors included), this function also does this.
#' @export
size <- function(x, d) { size <- function(x, d) {
# Determining the number of dimensions # Determining the number of dimensions
if (all(is.na(x))) {
if (missing(d)) {
return(c(0, 0))
} else {
return(ifelse(d <= 2, 0, 1))
}
}
if (length(x) == 1) { if (length(x) == 1) {
# x is surely a scalar # x is surely a scalar
return(1) return(1)