Skip to content

Commit

Permalink
avoid collapsing numeric fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed Jan 10, 2019
1 parent 73cc8d9 commit 845cc4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/set_nml.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ set_nml <- function(glm_nml, arg_name, arg_val, arg_list = NULL){
# get appropriate block to place val within ** assumes no duplicate param names in other blocks **
blck <- get_block(glm_nml,arg_name)
arg_name <- get_arg_name(arg_name)
if(length(arg_val) > 1){
if(length(arg_val) > 1 & is.character(arg_val)){
arg_val <- paste0(arg_val, collapse = ",")
}
glm_nml[[blck]][[arg_name]] <- arg_val
Expand Down
19 changes: 16 additions & 3 deletions tests/testthat/test-nml.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,34 @@ test_that("can read in nml with vector for logicals", {
expect_is(get_nml_value(nml, 'flt_off_sw'), 'logical')
})

test_that("can read and write nml with vectors for character fields", {
# read vectors
test_that("can read and write nml with vectors", {
# read character vectors
glm_nml <- read_nml()
glm_nml <- set_nml(glm_nml, arg_list = list(
'inflow_fl' = c("yahara.csv", "yahara2.csv")))
expect_equal(
length(get_nml_value(glm_nml, arg_name = "inflow_fl")),
1)

# write vectors
# read numeric vectors
glm_nml <- read_nml()
glm_nml <- set_nml(glm_nml, arg_list = list(
'A' = c(1, 2, 3)))
expect_true(
length(get_nml_value(glm_nml, arg_name = "A") > 1))

# write character vectors
write_path <- paste0(tempdir(), 'glm2.nml')
write_nml(glm_nml, file = write_path)
expect_equal(
length(get_nml_value(read_nml(write_path), arg_name = "inflow_fl")),
1)

# write numeric vectors
write_path <- paste0(tempdir(), 'glm2.nml')
write_nml(glm_nml, file = write_path)
expect_true(
length(get_nml_value(read_nml(write_path), arg_name = "A")) > 1)
})

test_that("can read values from an nml file", {
Expand Down

0 comments on commit 845cc4f

Please sign in to comment.