From c63a41f968c6e8407eeeebff5b33a934bbc71537 Mon Sep 17 00:00:00 2001 From: Barbara Kemper Date: Wed, 1 Feb 2023 18:43:28 +0000 Subject: [PATCH] check for empty list in setListValue --- R/swat.R | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/R/swat.R b/R/swat.R index 11e9d36..33fe79f 100755 --- a/R/swat.R +++ b/R/swat.R @@ -2205,16 +2205,19 @@ setListValue <- function(sw_values, i, key, value) { { sw_sublist <- sw_values$createListAt(i, key, length(value)) swat::errorcheck(sw_values) - for ( j in 1:length(value) ) + if ( length(value) > 0 ) { - if ( is.null(names(value[j])) || nchar(names(value[j])) == 0 ) - { - setListValue(sw_sublist, j-1, '', value[[j]]) - } - else - { - setListValue(sw_sublist, j-1, names(value[j]), value[[j]]) - } + for ( j in 1:length(value) ) + { + if ( is.null(names(value[j])) || nchar(names(value[j])) == 0 ) + { + setListValue(sw_sublist, j-1, '', value[[j]]) + } + else + { + setListValue(sw_sublist, j-1, names(value[j]), value[[j]]) + } + } } return (i + 1) }