beautifyR icon indicating copy to clipboard operation
beautifyR copied to clipboard

Beautify Comment: Keep `-` and don't break inline code

Open SchmidtPaul opened this issue 2 years ago • 10 comments

Hi, thanks for the great addin - I am using Beautify Comment on a regular basis. However, I find myself manually

  1. re-inserting - hyphens/dashes, because they are always removed
  2. removing linebreaks to make inline code r mean(c(1,2)) appear on a single line

Do you think there is a better way to handle these?

SchmidtPaul avatar Feb 15 '22 11:02 SchmidtPaul

Hey @SchmidtPaul, glad to hear you like the addin. Could you provide one (or two) sample tables against which I could develop the fix?

mwip avatar Apr 13 '22 11:04 mwip

Sure, but note I am talking about beautifying comments, not tables:

Here is a sample:

# This is my dash-dash word. And this right here is inline code `r mean(c(1,2))` that is
# separated into two lines when beautifying this comment.

which currently is being beautifyed into this:

# This is my dash dash word. And this right here is inline code `r
# mean(c(1,2))` that is separated into two lines when beautifying this
# comment.

Notice the missing - and the linebreak within the inline code. Thus, I would like it to be beautifyed to this instead:

# This is my dash-dash word. And this right here is inline code 
# `r mean(c(1,2))` that is separated into two lines when beautifying 
# this comment.

SchmidtPaul avatar Apr 13 '22 13:04 SchmidtPaul

Sorry to bother you, but any news about this? I am still re-inserting all the dashes after beautifying my comments 😅

SchmidtPaul avatar May 25 '22 08:05 SchmidtPaul

@SchmidtPaul, sorry for taking so long. Was busy with my thesis. I added two fixes to for this. I'd kindly ask you to test this. Maybe throw in some odd-balls, too. Once you confirm, I'll merge this.

Just install the patched version via

devtools::install_github("mwip/beautifyR", ref="dont_split_inline_code_and_dashes")

Thanks for your participation in this.

mwip avatar May 28 '22 20:05 mwip

Thanks for taking the time!

So, the example from above works perfectly fine. However, I then tried this one here:

#' Bzgl. der Behandlungseffekte ist der Versuch prinzipiell 3 faktoriell, allerdings ist `Sorte` geschachtelt im Effekt `Typ`, da jede Sorte nur
#' genau zu einem Typ gehört und ein Sorten-übergreifender Effekt des Typs
#' explizit untersucht werden soll. Somit gibt es die festen Effekte
#' `Intensität`, `Saatzeit`, `Typ` und `Typ:Sorte` und all deren Wechselwirkungen. Bzgl. der Designeffekte werden alle oben genannten
#' Effekte als zufällig ins Modell aufgenommen: Wiederholung (`Wdh`),
#' Großteilstück (`GT`), Kleinteilstück (`KT`), und Doppelplot (`DP`).

and it was beautified to

#' Bzgl. der Behandlungseffekte ist der Versuch prinzipiell 3 faktoriell,
#' allerdings ist
#'
#' `Sorte` geschachtelt im Effekt `Typ`, da jede Sorte nur genau zu einem Typ gehört und ein Sorten-übergreifender Effekt des Typs explizit untersucht werden soll. Somit gibt es die festen Effekte `Intensität`, `Saatzeit`, `Typ`
#' und
#'
#' `Typ:Sorte` und all deren Wechselwirkungen. Bzgl. der Designeffekte werden alle oben genannten Effekte als zufällig ins Modell aufgenommen: Wiederholung (`Wdh`), Großteilstück (`GT`), Kleinteilstück (`KT`), und Doppelplot (`DP`).

which seems odd?! Can you replicate this? I mean the dash is still there 👍 But somehow linebreaks are inserted at the wrong positions?

SchmidtPaul avatar May 30 '22 07:05 SchmidtPaul

Thanks for taking the time to test it, I really appreciate it. I did not have single words in back ticks in mind. I'll fix it and let you know in the next days. Hope you are up for another test.

mwip avatar Jun 01 '22 06:06 mwip

I fixed it in 2cfbe07. Could you try again?

devtools::install_github("mwip/beautifyR", ref="dont_split_inline_code_and_dashes")

mwip avatar Jun 02 '22 14:06 mwip

Yes, I tried out several comments and I think we can close this issue now. Thanks a lot!

SchmidtPaul avatar Jun 03 '22 07:06 SchmidtPaul

Thank you for your patience and constructive criticism. Hope you enjoy working with beautifyR :+1:

mwip avatar Jun 03 '22 09:06 mwip

Hey, somehow I stumbled across a case where it still doesn't work right?

Before

#' Sidenote: One can also use the `dispformula = ~ 0` argument to set the error
#' variance to 0. Technically it is not being set to exactly 0, but to a very
#' small value defined as `sqrt(.Machine$double.eps)` (find more on this
#' [here](https://github.com/glmmTMB/glmmTMB/issues/653) and [here](https://schmidtpaul.github.io/MMFAIR/glmmtmbdispformula0.html)). As a consequence,
#' this can be seen as an alternative way of formulating the model for the special case of setting 
#' the error variance to 0. It was shown [here](https://github.com/glmmTMB/glmmTMB/issues/833#issuecomment-1182840849) that the resulting model is
#' indeed equivalent to fixing the error variance via the method shown above to
#' `start = list(betad = log(sqrt(.Machine$double.eps)))`.

After

#' Sidenote: One can also use the `dispformula = ~ 0` argument to set the
#' error variance to 0. Technically it is not being set to exactly 0, but to a
#' very small value defined as
#'
#' `sqrt(.Machine$double.eps)` (find more on this [here](https://github.com/glmmTMB/glmmTMB/issues/653) and [here](https://schmidtpaul.github.io/MMFAIR/glmmtmbdispformula0.html)). As a consequence, this can be seen as an alternative way of formulating the model for the special case of setting  the error variance to 0. It was shown [here](https://github.com/glmmTMB/glmmTMB/issues/833#issuecomment-1182840849) that the resulting model is indeed equivalent to fixing the error variance via the method shown above to `start = list(betad = log(sqrt(.Machine$double.eps)))`.

SchmidtPaul avatar Jul 13 '22 09:07 SchmidtPaul

Should be fixed. I am now using proper testing with testthat. Maybe you want to have a look at tests/testthat/test-beautifyComment.R whether This is right. The latest example comment will now be beautified to:

#' Sidenote: One can also use the `dispformula = ~ 0` argument to set the
#' error variance to 0. Technically it is not being set to exactly 0, but to a
#' very small value defined as `sqrt(.Machine$double.eps)` (find more on this
#' [here](https://github.com/glmmTMB/glmmTMB/issues/653) and
#' [here](https://schmidtpaul.github.io/MMFAIR/glmmtmbdispformula0.html)). As
#' a consequence, this can be seen as an alternative way of formulating the
#' model for the special case of setting the error variance to 0. It was shown
#' [here](https://github.com/glmmTMB/glmmTMB/issues/833#issuecomment-1182840849)
#' that the resulting model is indeed equivalent to fixing the error variance
#' via the method shown above to
#' `start = list(betad = log(sqrt(.Machine$double.eps)))`.

Hope this is what you were looking for. And again, sorry for the late response.

mwip avatar Aug 23 '22 18:08 mwip