Skip to content

Instantly share code, notes, and snippets.

View maurolepore's full-sized avatar

Mauro Lepore maurolepore

View GitHub Profile
@maurolepore
maurolepore / guideline_writing.md
Last active January 11, 2017 01:36
guideline_writing
@maurolepore
maurolepore / moderate.md
Last active February 17, 2017 04:53
moderate
@maurolepore
maurolepore / keyboard_shortcuts.md
Last active July 14, 2017 15:33
keyboard_shortcuts

RStudio

  • see shortcuts: Shift + Alt + K

  • Find in current file: Ctrl + F

  • Find in project (files, functions, objects): Ctrl + Shift + F

  • Ctrl shift F10, restart session

Adapted from code by Shameema Jafferjee Esufali

add_subquadrat <- function(df) {
  x1 <- c(0, 10, 10, 0)
  x2 <- c(10, 20, 20, 10)
  y1 <- c(0, 0, 10, 10)
  y2 <- c(10, 10, 20, 20)

 df_list &lt;- replicate(4, data.frame(NULL, stringsAsFactors = FALSE))
library(baad.data)
library(tidyverse)
#> + ggplot2 2.2.1        Date: 2017-10-04
#> + tibble  1.3.4           R: 3.4.1
#> + tidyr   0.7.1          OS: Windows 10 x64
#> + readr   1.1.1         GUI: RTerm
#> + purrr   0.2.3      Locale: English_Australia.1252
#> + dplyr   0.7.2          TZ: America/New_York
#> + stringr 1.2.0      
@maurolepore
maurolepore / namespace.md
Created November 10, 2017 15:59
Minimum information to deal with NAMESPACE issues.

Read this if one of the following applies to you:

  • You are using library(package) or require(package) inside your functions
  • You don't know exactly when you need the syntax package::function() or package:::function() as opposed to function().

If you are using functions from other packages inside functions of your own package, then you are dealing with NAMESPACE issues. NAMESPACE is one of the most confusing parts of an R package. Prepare for your brain to hurt a bit. This information will not answer all your questions, but it will rise an alarm that may save you time and trouble.

From http://r-pkgs.had.co.nz/namespace.html, find section "Imports" and read its introduction and also the subheading "R functions".

R functions

  • Add dplyr and tidyr to DESCRIPTION.
  • Refer to functions as dplyr::FUNCTION() and tidyr::FUNCTION().
  • Remove all !! and := because in this case you don't need them.
  • Add new_df at the end so that it is returned.
  • Rebuild, reload, rerun myfunction.

image

@maurolepore
maurolepore / code_good_practice.md
Last active November 28, 2017 17:45
code_good_practice
  • Don't hard code settings (e.g. figure colours), read them from a file via read_settings().

The code is more readable and flexible than it would be if a value were hard-coded. You don't need to change the program to change titleBar.color ; you simply change the contents of the source that's read by"

-― from "Code Complete (Developer Best Practices)" by Steve McConnell, http://a.co/b75gLyw

  • Prefer long informative names over short uninformative ones (8-20 characters is ok)

In modern languages like C++, Java, and Visual Basic, you can create names of virtually any length; you have almost no reason to shorten meaningful names.

C F
-10 °C 14.0 °F
-9 °C 15.8 °F
-8 °C 17.6 °F
-7 °C 19.4 °F
-6 °C 21.2 °F
-5 °C 23.0 °F
-4 °C 24.8 °F
-3 °C 26.6 °F