Hi both,
I encountered the same issues when using the latest Apollo package 0.3.9
I had no such issues in earlier version.
Since I couldnt figure the reason why when I have identical dataset but able to run in earlier version , but not the latest version.
I looked into the source code of the longtowide function
and found one particular issue in the source code.
Code: Select all
longData$ID_obs <- interaction(
longData[, idColumn],
longData[, obsColumn],
drop = TRUE,
lex.order = TRUE
)
In the source code , we can see that apollo produce internal ID_obs as factor variable by default when using interaction () function.
However, the subsequent code
rle () function does not directly accept "factor" format variable, therefore, I encountered the same issues.
rle(generic_pattern$ID_obs: ‘x’ must be a vector of atomic type
A workaround that worked in my case is to make a local copy of apollo function and an apollo environment, then add rle(as.character(x) to allow rle function to accept factor variables. basically, a override of the function without change the source code, of course, this can be changed in source code I believe.
Code: Select all
# Create a local copy of Apollo's function
apollo_longToWide_fixed <- apollo::apollo_longToWide
# Create an environment inheriting Apollo's namespace
fix_env <- new.env(
parent = environment(apollo_longToWide_fixed)
)
# Override rle() locally to handle factor variables
fix_env$rle <- function(x) {
base::rle(as.character(x))
}
# Apply the fix only to the copied function
environment(apollo_longToWide_fixed) <- fix_env
I hope this helps
Kind regards
Jack