我有以下数据:
data <- list( name = "Chris",
children_names = c("Alex", "John")
)使用R的模板引擎https://github.com/edwindj/whisker,当呈现时,我希望得到这个输出:
I am Chris
My children are:
Child No 1 is Alex
Child No 2 is John这是我目前的代码:
library(whisker)
template <-
'I am {{name}}
My children are:
{{children_names}}
'
data <- list( name = "Chris",
children_names = c("Alex", "John")
)
text <- whisker.render(template, data)
cat(text)
# which produces:
# I am Chris
# My children are:
# Alex,John这不是我想要的。正确的方法是什么?
发布于 2017-12-06 23:52:56
您可能已经知道了,但如果您还没有:
library(whisker)
template <-
'I am {{name}} \n
My children are: \n
{{#children_names}}
Child No {{number}} is {{cname}}
{{/children_names}}'
data <- list(
name = "Chris",
children_names = list(
list(cname = "Alex", number = 1), list(cname = "John", number = 2)
)
)
text <- whisker.render(template, data)
cat(text)
# I am Chris
#
# My children are:
#
# Child No 1 is Alex
# Child No 2 is Johnhttps://stackoverflow.com/questions/46581300
复制相似问题