AntoineSoetewey / statsandr

A blog on statistics and R aiming at helping academics and professionals working with data to grasp important concepts in statistics and to apply them in R. See www.statsandr.com
http://statsandr.com/
35 stars 15 forks source link

blog/tips-and-tricks-in-rstudio-and-r-markdown/ #17

Closed utterances-bot closed 3 years ago

utterances-bot commented 3 years ago

Tips and tricks in RStudio and R Markdown - Stats and R

This article illustrates the main tips, tricks and shortcuts you can use in RStudio and R Markdown to write code more quickly and more efficiently

https://statsandr.com/blog/tips-and-tricks-in-rstudio-and-r-markdown/

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35:

Great article! Thank you so much.

What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35:

Great article! Thank you so much.

What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

Comment written by Antoine Soetewey on January 27, 2020 18:10:27:

Thanks for your comment Eyayaw.

I just tried on my computer, cmd + shift + A reformats the code following the guidelines. However, ctrl + I does nothing on my side.

What does this shortcut do on your side?

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35: Great article! Thank you so much. What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

Comment written by Antoine Soetewey on January 27, 2020 18:10:27:

Thanks for your comment Eyayaw.

I just tried on my computer, cmd + shift + A reformats the code following the guidelines. However, ctrl + I does nothing on my side.

What does this shortcut do on your side?

Comment written by Eyayaw T. Beze on January 27, 2020 18:16:54:

The shortcut does alignment: for example ctrl + i change this code

function(x) {format(x, digits = 2, big.mark = ",") }

into

function(x) {format(x, digits = 2, big.mark = ",") }

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35: Great article! Thank you so much. What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

Comment written by Antoine Soetewey on January 27, 2020 18:10:27: Thanks for your comment Eyayaw. I just tried on my computer, cmd + shift + A reformats the code following the guidelines. However, ctrl + I does nothing on my side. What does this shortcut do on your side?

Comment written by Eyayaw T. Beze on January 27, 2020 18:16:54:

The shortcut does alignment: for example ctrl + i change this code

function(x) {format(x, digits = 2, big.mark = ",") }

into

function(x) {format(x, digits = 2, big.mark = ",") }

Comment written by Antoine Soetewey on January 27, 2020 18:21:28:

Interesting.

I tried with the code you provided, nothing changes when I use ctrl + I. When I use cmd + Shift + A, the code is well formatted, as expected.

Anyway, if on your side you see the exact same result with both shortcuts, then you can choose which one to use :)

Hope it helps!

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35: Great article! Thank you so much. What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

Comment written by Antoine Soetewey on January 27, 2020 18:10:27: Thanks for your comment Eyayaw. I just tried on my computer, cmd + shift + A reformats the code following the guidelines. However, ctrl + I does nothing on my side. What does this shortcut do on your side?

Comment written by Eyayaw T. Beze on January 27, 2020 18:16:54: The shortcut does alignment: for example ctrl + i change this code function(x) {format(x, digits = 2, big.mark = ",") } into function(x) {format(x, digits = 2, big.mark = ",") }

Comment written by Antoine Soetewey on January 27, 2020 18:21:28:

Interesting.

I tried with the code you provided, nothing changes when I use ctrl + I. When I use cmd + Shift + A, the code is well formatted, as expected.

Anyway, if on your side you see the exact same result with both shortcuts, then you can choose which one to use :)

Hope it helps!

Comment written by Eyayaw T. Beze on January 27, 2020 18:27:12:

I don't know why but it does some alignment on my Mac.

In fact what it does is "reindents line" (https://support.rstudio.com...).

Thank you for the replies. Have a good one.

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35: Great article! Thank you so much. What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

Comment written by Antoine Soetewey on January 27, 2020 18:10:27: Thanks for your comment Eyayaw. I just tried on my computer, cmd + shift + A reformats the code following the guidelines. However, ctrl + I does nothing on my side. What does this shortcut do on your side?

Comment written by Eyayaw T. Beze on January 27, 2020 18:16:54: The shortcut does alignment: for example ctrl + i change this code function(x) {format(x, digits = 2, big.mark = ",") } into function(x) {format(x, digits = 2, big.mark = ",") }

Comment written by Antoine Soetewey on January 27, 2020 18:21:28: Interesting. I tried with the code you provided, nothing changes when I use ctrl + I. When I use cmd + Shift + A, the code is well formatted, as expected. Anyway, if on your side you see the exact same result with both shortcuts, then you can choose which one to use :) Hope it helps!

Comment written by Eyayaw T. Beze on January 27, 2020 18:27:12:

I don't know why but it does some alignment on my Mac.

In fact what it does is "reindents line" (https://support.rstudio.com...).

Thank you for the replies. Have a good one.

Comment written by Antoine Soetewey on January 27, 2020 18:33:38:

Thanks for the link. If I understand well, cmd + I on Mac reindents line only. So it seems to me that it does not do anything else, for instance adding white spaces, etc.

Cmd + Shift + A reindents line in addition to other formatting rules.

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35: Great article! Thank you so much. What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

Comment written by Antoine Soetewey on January 27, 2020 18:10:27: Thanks for your comment Eyayaw. I just tried on my computer, cmd + shift + A reformats the code following the guidelines. However, ctrl + I does nothing on my side. What does this shortcut do on your side?

Comment written by Eyayaw T. Beze on January 27, 2020 18:16:54: The shortcut does alignment: for example ctrl + i change this code function(x) {format(x, digits = 2, big.mark = ",") } into function(x) {format(x, digits = 2, big.mark = ",") }

Comment written by Antoine Soetewey on January 27, 2020 18:21:28: Interesting. I tried with the code you provided, nothing changes when I use ctrl + I. When I use cmd + Shift + A, the code is well formatted, as expected. Anyway, if on your side you see the exact same result with both shortcuts, then you can choose which one to use :) Hope it helps!

Comment written by Eyayaw T. Beze on January 27, 2020 18:27:12: I don't know why but it does some alignment on my Mac. In fact what it does is "reindents line" (https://support.rstudio.com...). Thank you for the replies. Have a good one.

Comment written by Antoine Soetewey on January 27, 2020 18:33:38:

Thanks for the link. If I understand well, cmd + I on Mac reindents line only. So it seems to me that it does not do anything else, for instance adding white spaces, etc.

Cmd + Shift + A reindents line in addition to other formatting rules.

Comment written by Eyayaw T. Beze on January 27, 2020 18:42:28:

True. I was not satisfied with ctrl + i to begin with, glad I discovered the trick today thanks to you.

AntoineSoetewey commented 3 years ago

Comment written by Eyayaw T. Beze on January 27, 2020 18:06:35: Great article! Thank you so much. What is the difference between cmd + Shift + A on Mac and ctrl + i on mac? Both can be used to align codes, right?

Comment written by Antoine Soetewey on January 27, 2020 18:10:27: Thanks for your comment Eyayaw. I just tried on my computer, cmd + shift + A reformats the code following the guidelines. However, ctrl + I does nothing on my side. What does this shortcut do on your side?

Comment written by Eyayaw T. Beze on January 27, 2020 18:16:54: The shortcut does alignment: for example ctrl + i change this code function(x) {format(x, digits = 2, big.mark = ",") } into function(x) {format(x, digits = 2, big.mark = ",") }

Comment written by Antoine Soetewey on January 27, 2020 18:21:28: Interesting. I tried with the code you provided, nothing changes when I use ctrl + I. When I use cmd + Shift + A, the code is well formatted, as expected. Anyway, if on your side you see the exact same result with both shortcuts, then you can choose which one to use :) Hope it helps!

Comment written by Eyayaw T. Beze on January 27, 2020 18:27:12: I don't know why but it does some alignment on my Mac. In fact what it does is "reindents line" (https://support.rstudio.com...). Thank you for the replies. Have a good one.

Comment written by Antoine Soetewey on January 27, 2020 18:33:38: Thanks for the link. If I understand well, cmd + I on Mac reindents line only. So it seems to me that it does not do anything else, for instance adding white spaces, etc. Cmd + Shift + A reindents line in addition to other formatting rules.

Comment written by Eyayaw T. Beze on January 27, 2020 18:42:28:

True. I was not satisfied with ctrl + i to begin with, glad I discovered the trick today thanks to you.

Comment written by Antoine Soetewey on January 27, 2020 23:25:25:

Glad you discovered this shortcut.

As you like shortcuts, you may be interested in the article I just published: https://www.statsandr.com/blog/rstudio-addins-or-how-to-make-your-coding-life-easier/. It is about RStudio addins.

AntoineSoetewey commented 3 years ago

Comment written by kieroneil on March 15, 2020 21:40:19:

Very useful shortcuts to speed development. Thanks for sharing.

AntoineSoetewey commented 3 years ago

Comment written by kieroneil on March 15, 2020 21:40:19:

Very useful shortcuts to speed development. Thanks for sharing.

Comment written by Antoine Soetewey on March 15, 2020 21:42:51:

Glad you found it useful!