harrelfe / Hmisc

Harrell Miscellaneous
Other
208 stars 81 forks source link

Preventing failures in latexTranslate due to missing values #43

Closed nutterb closed 8 years ago

nutterb commented 8 years ago

In Hmisc 3.17-5, the following code produces and error:

latexTranslate(c(NA, "$", "\\", NA, "<", "gibberish", NA),
               inn = "gibberish",
               out = "ig-pay atin-lay")

Error in if (!any(k)) next : missing value where TRUE/FALSE needed

Might you consider some small modifications allow the translation to proceed while ignoring the NA values.

latexTranslate(c(NA, "$", "\\", NA, "<", "gibberish", NA),
               inn = "gibberish",
               out = "ig-pay atin-lay")
[1] NA                "\\$"             "\\"              NA               
[5] "$<$"             "ig-pay atin-lay" NA 
harrelfe commented 8 years ago

I think those are more extensive changes than what is really needed. I just changed the first line of code inside the function to text <- ifelse(is.na(object), '', as.character(object)) I will commit this change in a moment.

nutterb commented 8 years ago

I had actually been working in a context where I had intended to preserve the NA values for use later on, but I can make an argument that any other processing I do should probably be done before getting to latexTranslate. With your solution, would it make sense to add an additional argument, na='' and combine that with text <- ifelse(is.na(object), '', as.character(object))? (If not, I'll just do this myself before calling latexTranslate)

Thanks for the quick response.

harrelfe commented 8 years ago

I just added the na argument to latexTranslate

nutterb commented 8 years ago

Excellent! Thanks so much.