开发者

making a complex yaml from R

I am trying to make yaml format file from R. I know there is a package for such a 开发者_StackOverflow社区job, but its example is so simple and my object is a bit more tricky !!

so I would like to make something like the following but I don't know how should I shape it as R object (dataframe?!):

tree:
  format: newick
  translate: ./My_example-1.translation
  file: ./Xtol_example-1.tree
tracks:
  - class: colorstrip
    source: ./My_example-1.catdomain

    rel_height: 0.6
    title: Catalytic domain
  - class: colorstrip
    source: ./My_example-1.kingdom
    rel_height: 0.6
    title: Itsname
  - class: colorstrip
    source: ./My_example-1.temp


My short advice - don't use yaml with R.

(Editor's note: It appears that the problems documented here have since been fixed--see the comments.)

Issue 1

The yaml package in R seems to be unusable but the real issue seems to be with R. But then again, I hadn't bothered with yaml till I saw this question, so may be there are gaps in my understanding of the whole issue.

To successfully create the yaml in question, at some point, we'll have to have a vector of lists which is not a list (for tracks). I think there is no way to do that in R. As soon as we add elements to a vector which are lists, the vector turns into a list. I guess a vector can only take elements of a fixed size (hence simplified operations, hence good performance and hence the abundance of advice to vectorize).

For simple atomic types like numeric, integer etc, I suppose the R interpreter already knows about their size (which is fixed). But if the element is a list, then that luxury is lost, and the vector is converted into a list so that it may deal with the varying sizes of the elements (lists).

Hence, there can not be a vector of lists which is not a list, and we have serious problems transforming data to and from yaml in R.

Issue 2

The R yaml package is poorly documented, and I can't figure out how does it solve the issue. I guessed that it might have used a convention to get around it. So what I tried to do was this (and this approach would also have solved your problem) - import the yaml as an R object and then try to convert that R object into yaml.

library("yaml")
z <- yaml.load(
"tree:
  format: newick
  translate: ./My_example-1.translation
  file: ./Xtol_example-1.tree
tracks:
  - class: colorstrip
    source: ./My_example-1.catdomain

    rel_height: 0.6
    title: Catalytic domain
  - class: colorstrip
    source: ./My_example-1.kingdom
    rel_height: 0.6
    title: Itsname
  - class: colorstrip
    source: ./My_example-1.temp")
names(z)
names(z$tracks)
y <- as.yaml(z)

as you would see, it doesn't work. I think you can save yourself a lot of pain by not trying to use yaml with R. You could consider using XML or something like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜