Page 1 of 1

Long to Wide issue

Posted: 02 Oct 2026, 20:53
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!

Re: Long to Wide issue

Posted: 12 Oct 2026, 15:53
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

Re: Long to Wide issue

Posted: 12 Oct 2026, 20:55
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.

Re: Long to Wide issue

Posted: 16 Oct 2026, 09:33
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

Re: Long to Wide issue

Posted: 22 Oct 2026, 16:10
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