stefano-meschiari / latex2exp

Use LaTeX in R graphics.
Other
185 stars 10 forks source link

Type stability of new parser #40

Closed mariusbarth closed 2 years ago

mariusbarth commented 2 years ago

Hi @stefano-meschiari,

Thank you very much for this awesome package! After installing v0.9.0, I ran into problems with my own functions that build on TeX(). I could pin down the problem easily, but I think it might be worth discussing whether or not something should be changed in latex2exp, too.

Here is the issue: If an empty character is passed (i.e., TeX("")), the new return value in version 0.9.0 has length zero, while in earlier versions it was an empty expression (i.e., the same as from expression("")). I believe the old behaviour is preferable (and "right") because it makes the output more predictable and length("") equals 1 in R.

What do you think?

Best regards, Marius

stefano-meschiari commented 2 years ago

Could you check if PR #42 fixes this issue?

You can install it via

devtools::install_github("stefano-meschiari/latex2exp", ref="0.9.2")
mariusbarth commented 2 years ago

Of course! I think this is good:

> str(TeX(" "))
Classes 'latexexpression', 'expression' length 1 expression(" ")
  ..- attr(*, "latex")= chr " "
  ..- attr(*, "plotmath")= chr "' '"
> str(TeX(""))
Classes 'latexexpression', 'expression' length 1 expression("")
  ..- attr(*, "latex")= chr ""
  ..- attr(*, "plotmath")= chr ""

Thanks a lot!

stefano-meschiari commented 2 years ago

No problem, thank you so much for the report and your kind words.

I will submit a new version to CRAN over the next few days.