survival icon indicating copy to clipboard operation
survival copied to clipboard

Patch fix for long formula names

Open jwallib opened this issue 3 years ago • 3 comments

Patching a bug caused by an issue with the terms function in the stats package.

For very long feature names, such as those introduced by using the ridge function with many parameters the terms function splits the variable names by inserting a new line character.

Heres a demo example: terms(as.formula(paste0('~ridge(',paste0('variable',1:50,collapse = ','),',theta = 1,scale = TRUE)'))) returns an object where attr(,"term.labels") and attr(,"factors") names have been split by a new line character '\n' (for me this was around variable 42).

The reason this is a problem is because later on in the coxph function (lines 541 and 543 here) it tries to match a version of the string with the newline character (attr(Terms, 'term.labels') and names(assign)) and one without (pname). It fails and returns NA. This in turn falsely triggers the error on line 542.

jwallib avatar Jul 07 '21 15:07 jwallib

Please take note of the very first lines in coxph.r. --- the file is automatically derived from the actual source in the now directory. Any patches have to be there.

Patching a bug caused by an issue with the terms function in the stats package.

For very long feature names, such as those introduced by using the ridge function with many parameters the terms function splits the variable names by inserting a new line character.

Heres a demo example: terms(as.formula(paste0('~ridge(',paste0('variable',1:50,collapse = ','),',theta = 1,scale = TRUE)'))) returns an object where attr(,"term.labels") and attr(,"factors") names have been split by a new line character '\n' (for me this was around variable 42).

The reason this is a problem is because later on in the coxph function (lines 541 and 543 here) it tries to match a version of the string with the newline character (attr(Terms, 'term.labels') and names(assign)) and one without (pname). It fails and returns NA. This in turn falsely triggers the error on line 542.

therneau avatar Jul 07 '21 22:07 therneau

Typo in the last message: the "noweb" directory. (Actually, I typed correctly but a spell checker intervened).

therneau avatar Jul 07 '21 22:07 therneau

Ahh sorry about that, I have now done the patch in the coxph.Rwd file in the noweb directory and rerun "make all -f Makefile".

jwallib avatar Jul 08 '21 08:07 jwallib