Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move info from bluspice to this #18

Open
Felixmil opened this issue Apr 17, 2024 · 2 comments
Open

Move info from bluspice to this #18

Felixmil opened this issue Apr 17, 2024 · 2 comments

Comments

@Felixmil
Copy link
Collaborator

From: https://wiki.esqlabs.com/wiki/Software/R_tips_and_tricks

RStudio

Useful shortcuts

  • Find in files: Ctrl + Shift + F
  • Insert assignment operator (<-): Alt + -
  • Show all shortcuts: Alt + Shift + K
  • Reload package:Cmd + Shift + L
  • Navigate to: Ctrl + .
  • Generate Doc: Ctrl + Shift + D
  • Run unit tests: Ctrl + Shift + T
  • Navigate to implementation: Mouse over + F2 or CTRL + Mouse Click
  • Un-/Comment line/selection: Ctrl + Shift + C
  • Select all occurrences of the selected variable: CTRL + SHIFT + ALT + M
  • Cursor-Select multiple lines: Ctrl + Alt + Up/Down

Profiling

Profiling of code can be done within R-Studio with the package profvis, a descirption of the process is given here . In short, pass the code to be profiled as argument to the function profvis:

profvis({
  data(diamonds, package = "ggplot2")

  plot(price ~ carat, data = diamonds)
  m <- lm(price ~ carat, data = diamonds)
  abline(m, col = "red")
})

Markdown

Performance

If you want to see if a vector contains a single value, any(x == 10) is much faster than 10 %in% x because testing equality is simpler than testing set inclusion.
unlist(x, use.names = FALSE) is much faster than unlist(x).
A pernicious source of slow R code is growing an object with a loop. Whenever you use c(), append(), cbind(), rbind(), or paste() to create a bigger object, R must first allocate space for the new object and then copy the old object to its new home. If you repeat this many times, like in a for loop, this can be quite expensive.

External sources

General R

List of useful external information about R and RStudio.

ggplot2

@dlefaudeux
Copy link
Collaborator

And from esqlabsR github wiki (more or less the same as in bluespice):
https://github.com/esqLABS/esqlabsR/wiki/R-useful-information

@Felixmil
Copy link
Collaborator Author

related to #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants