library(yaml)
qq <- list(
n = list(c('foo',''), c('bar','bar')),
m = list(c('foo',''))
);
identical(yaml.load(as.yaml(qq)), qq);
FALSE
qq <- list(
n = list(c('foo',''), c('bar','bar')),
m = list(c('foo',''), c('bar', 'bar')
);
identical(yaml.load(as.yaml(qq)), qq);
TRUE
我正在尝试传入一个yaml文件,其中m应该是长度为1的列表。
当m是长度为1的列表时,不确定为什么这不起作用,但是如果长度为2,则完全按预期工作?
yaml_2.1.11
帮助表示感谢,谢谢!
答案 0 :(得分:0)
我不知道为什么,但看起来你可以通过简单地为列表元素命名来解决这个问题。
library(yaml)
test <- within(test <- list(), {
len1 <- list('foo')
len2 <- list('foo', 'bar')
len1.named <- list(n = 'foo')
len2.named <- list(n = 'foo', m = 'bar')
len1.nest <- list(list('foo'))
len2.nest <- list(list('foo', 'bar'))
len1.nest.named <- list(list(n = 'foo'))
len2.nest.named <- list(list(n = 'foo', m = 'bar'))
qq <- list(n = list(c('foo',''), c('bar','bar')),
m = list(c('foo','')))
qq.named <- list(n = list(c('foo',''), c('bar','bar')),
m = list(x = c('foo','')))
})
lapply(test, function(x) identical(x, yaml.load(as.yaml(x))))
# $len1
# [1] FALSE
#
# $len2
# [1] FALSE
#
# $len1.named
# [1] TRUE
#
# $len2.named
# [1] TRUE
#
# $len1.nest
# [1] FALSE
#
# $len2.nest
# [1] FALSE
#
# $len1.nest.named
# [1] TRUE
#
# $len2.nest.named
# [1] TRUE
#
# $qq
# [1] FALSE
#
# $qq.named
# [1] TRUE