data.tree icon indicating copy to clipboard operation
data.tree copied to clipboard

as.Node.data.frame raises error when column name of data.frame equals the name of one node

Open simschul opened this issue 3 years ago • 1 comments

Thank you so much for your very helpful R-package! I encountered one issue: I get an error message (Error: $ operator is invalid for atomic vectors) when converting the following data.frame to a data.tree:

x <- data.frame(
  pathString = c( 'A',  'A/foo'), 
  foo = 'bar' 
)
y <- as.Node(x)

The problem disappears when changing either the column name or the name of the node, thus I assume that the reason for the problem is that both the second node and the column of x are named foo:

x <- data.frame(
  pathString = c('A',  'A/bar'), 
  foo = 'bar' 
)
y <- as.Node(x)
y

... no problems ....

Moreover, everything works as expected when deleting the parent (root) node:

x <- data.frame(
  pathString = c('A/foo'), 
  foo = 'bar' 
)
y <- as.Node(x)

Do you have any ideas how to fix this?

simschul avatar Jan 26 '22 15:01 simschul

Hey, sorry for the late reply, and thanks for this! Would you mind to create a pull request with your changes? Thx!

gluc avatar Nov 11 '23 23:11 gluc