I am running into an issue when using the apollo_longToWide in version 0.3.9.
When I run it I get the following error:
Error in rle(generic_pattern$ID_obs: ‘x’ must be a vector of atomic type
In addition:
In ny*ax : NAs produced by integer overflow
Any help is appreciated!
Important: Read this before posting to this forum
- This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
- There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
- Before asking a question on the forum, users are kindly requested to follow these steps:
- Check that the same issue has not already been addressed in the forum - there is a search tool.
- Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
- Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
- Make sure that R is using the latest official release of Apollo.
- Users can check which version they are running by entering packageVersion("apollo").
- Then check what is the latest full release (not development version) at http://www.ApolloChoiceModelling.com/code.html.
- To update to the latest official version, just enter install.packages("apollo"). To update to a development version, download the appropriate binary file from http://www.ApolloChoiceModelling.com/code.html, and install the package from file
- If the above steps do not resolve the issue, then users should follow these steps when posting a question:
- provide full details on the issue, including the entire code and output, including any error messages
- posts will not immediately appear on the forum, but will be checked by a moderator first. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.
Long to Wide issue
-
stephanehess
- Site Admin
- Posts: 1373
- Joined: 24 Apr 2020, 16:29
Re: Long to Wide issue
Hi
can you provide us with more information, such as the column names and data types in the original data, plus the call you make with the settings, etc
Thanks
Stephane
can you provide us with more information, such as the column names and data types in the original data, plus the call you make with the settings, etc
Thanks
Stephane
Re: Long to Wide issue
Yes, sorry! I cannot include any data, as they are held in a secure server. These are panel data at the individual, year level.
id_num: (int) identifies the indiviudal across years
choice_id: (int) is a unique id_num-year grouping
alt_num: (int) is the alternatives in each choice set
choice: (True/False) is TRUE for the choice made and FALSE otherwise.
List of ASC's: I have a list of ASC's that are all integer values.
The call I use is:
The weird part is this was all working when I was using version 0.3.6, however I recently got the secure server to update the version to the latest available and now the issue has come up.
id_num: (int) identifies the indiviudal across years
choice_id: (int) is a unique id_num-year grouping
alt_num: (int) is the alternatives in each choice set
choice: (True/False) is TRUE for the choice made and FALSE otherwise.
List of ASC's: I have a list of ASC's that are all integer values.
The call I use is:
Code: Select all
database <- apollo_longToWide(longData = as.data.frame(choice_sets), longToWide_settings = list(
idColumn = "id_num", obsColumn = "choice_id", altColumn = "alt_num",
choiceColumn = "choice",
altSpecAtts = list of ASC's))-
jackhan1208
- Posts: 5
- Joined: 28 Apr 2025, 21:12
Re: Long to Wide issue
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.
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.
I hope this helps
Kind regards
Jack
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
)However, the subsequent code
Code: Select all
rle(generic_part$ID_obs)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_envKind regards
Jack
-
stephanehess
- Site Admin
- Posts: 1373
- Joined: 24 Apr 2020, 16:29
Re: Long to Wide issue
Hi
this is indeed a bug in 0.3.9 which is being fixed for 0.4.0. A development version should be on the website within a week or so, and the official release in early November
Stephane
this is indeed a bug in 0.3.9 which is being fixed for 0.4.0. A development version should be on the website within a week or so, and the official release in early November
Stephane