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?