0

I am trying to adapt the code found here to import employee data from an Excel file into a data frame and then use the as.node function from the data.tree package.

This is the code I have written so far

library(data.tree)
library(readxl)

baseframe <- read_excel("Test Emplist.xlsx")

baseframe$pathstring <- paste("CompanyName",
                        baseframe$LastName,
                        baseframe$FirstName,
                        sep = "/")

stafflist <- as.Node(baseframe)

The data frame is being created successfully. Below is the dput representation

> dput(head(baseframe))
structure(list(LastName = c("Vasa", "Vasa", "Pras", "Tang", "Sing", 
"Vats"), FirstName = c("Evan", "Koma", "Shil", "Hand", "Smri", 
"Saur"), pathstring = c("CompanyName/Vasa/Evan", "CompanyName/Vasa/Koma", 
"CompanyName/Pras/Shil", "CompanyName/Tang/Hand", "CompanyName/Sing/Smri", 
"CompanyName/Vats/Saur")), .Names = c("LastName", "FirstName", 
"pathstring"), row.names = c(NA, 6L), class = c("tbl_df", "tbl", 
"data.frame"))

but when I get to the line stafflist <- as.Node(baseframe) I am getting an error message saying

Error in strsplit(mypath, pathDelimiter, fixed = TRUE :
non-character argument

I'm guessing the as.node function calls another function called strsplit somewhere. I have tried running the function myself as so

strsplit(baseframe$pathstring, "/", fixed = TRUE)

which is running no problem. I'm not sure why the as.node function is throwing the error?

Leroy
  • 634
  • 1
  • 8
  • 33
  • Can you share `baseframe` object or perhaps simulate some data that returns the same error? – Roman Luštrik Jun 25 '19 at 09:51
  • Hi Roman, I have updated my question with an example of the data in the dataframe. Is this what you meant? – Leroy Jun 25 '19 at 10:00
  • More in terms of a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) which demonstrates (reproduces) the problem. – Roman Luštrik Jun 25 '19 at 11:06
  • Hi Roman, I have followed the link you provided and added the dput output of my dataframe. Hope this helps. Apologies, I'm a bit of a novice – Leroy Jun 25 '19 at 12:55

0 Answers0