2014-05-05 65 views
1
library(yaml)  

qq <- list(
     n = list(c('foo',''), c('bar','bar')), 
     m = list(c('foo','')) 
    ); 
identical(yaml.load(as.yaml(qq)), qq); 

FALSE傳遞YAML在R:在一個元件列表

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

我不知道爲什麼,但它看起來像你可能能夠解決這個問題,只需具有列表元素的名稱。

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