Important: Read this before posting to this forum

  1. 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.
  2. 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
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. 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
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. 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

Report bugs or highlight issues with Apollo functions. At a minimum, please include the part of the output where you believe the bug is manifested. Ideally, please share your model file.
Post Reply
Pmassey
Posts: 2
Joined: 02 Oct 2026, 16:55

Long to Wide issue

Post by Pmassey »

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!
stephanehess
Site Admin
Posts: 1373
Joined: 24 Apr 2020, 16:29

Re: Long to Wide issue

Post by stephanehess »

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
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Pmassey
Posts: 2
Joined: 02 Oct 2026, 16:55

Re: Long to Wide issue

Post by Pmassey »

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:

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))
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.
jackhan1208
Posts: 5
Joined: 28 Apr 2025, 21:12

Re: Long to Wide issue

Post by jackhan1208 »

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

Code: Select all

rle(generic_part$ID_obs)
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
stephanehess
Site Admin
Posts: 1373
Joined: 24 Apr 2020, 16:29

Re: Long to Wide issue

Post by stephanehess »

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
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply