Skip to content

Type conversion error in rec_with_table() during categorical to continuous variable processing #82

@DougManuel

Description

@DougManuel

Description

recodeflow::rec_with_table() fails with a type conversion error when processing CCHS categorical-to-continuous variables (e.g., height conversion from categorical codes to meters).

Error Message

Error in `[<-`:
! Assigned data `else_value` must be compatible with existing data.
ℹ Error occurred for column `value_to`.
Caused by error in `vec_assign()`:
! Can't convert <double> to <character>.

To Reproduce

Reproducible Example

library(cchsflow)  
load('data/variable_details.RData')

# Test data with categorical height codes (CCHS 2001 format)
test_data <- data.frame(
  ID = 1:2,
  HWTAGHT = c(26, 22)  # Code 26=5'9" (1.753m), Code 22=5'5" (1.651m)
)

# This works with cchsflow::rec_with_table()
result_cchsflow <- cchsflow::rec_with_table(
  data = test_data,
  variables = "HWTGHTM",
  database_name = "cchs2001_p",
  variable_details = variable_details
)
# Returns: 1.753, 1.651

# This fails with recodeflow::rec_with_table()
result_recodeflow <- recodeflow::rec_with_table(
  data = test_data,
  variables = "HWTGHTM", 
  database_name = "cchs2001_p",
  variable_details = variable_details
)
# Error: Can't convert <double> to <character>

Expected Behavior

recodeflow::rec_with_table() should work identically to cchsflow::rec_with_table() and successfully convert categorical codes to continuous values.

System Info

  • R version: 4.4.3
  • recodeflow version: 0.1.1
  • cchsflow version: 2.2.0

Additional Context

Technical Details

The error occurs in the internal recode_columns() function when trying to assign a numeric else_value (NA_real_) to a character column value_to in the log table. This suggests a type initialization issue in the logging mechanism during categorical-to-continuous variable processing.

Impact

This prevents migration from cchsflow::rec_with_table() to recodeflow::rec_with_table() for CCHS categorical variables, blocking the planned parallel processing strategy for v3.0.0 variables.

Workaround

Currently using cchsflow::rec_with_table() for all variables until this bug is resolved.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions