Skip to content

Instantly share code, notes, and snippets.

View maurolepore's full-sized avatar

Mauro Lepore maurolepore

View GitHub Profile
@maurolepore
maurolepore / time_it.md
Last active May 3, 2018 13:04
time_it(): Compare the performance of multiple functions; Profile functions. Keywords: system.time, microbenchmark
@maurolepore
maurolepore / r4ds.md
Last active May 7, 2018 12:58
Questions about R programming (R for data science, tidy tools, Hadley Wickham)

r4ds p. 85

[Use force when] creating closures with lapply() or a loop:

add <- function(x) {
  force(x)
  function(y) x + Y
}
lapply(1:10, add)
@maurolepore
maurolepore / dot_dot_dot.md
Created May 8, 2018 14:39
Dot dot dot, ellipses; best practices; arguments

Note that we call the first argument .x: whenever you use ... to take arbitrary data, it’s good practice to give the other argument names a . prefix. This eliminates any ambiguity about who owns the argument, and in this case makes it possible to set the x attribute.

--https://adv-r.hadley.nz/quasiquotation.html

@maurolepore
maurolepore / acknowledgments.md
Created May 13, 2018 22:08
Acknowledgments, contributors, thanks, commits, git2r.

From Jim Hester r-lib/devtools#1279

library(git2r)
r <- repository("C:/Users/LeporeM/Dropbox/git_repos/allodb")
c <- commits(r)
authors <- lapply(c, `slot`, "author")
names &lt;- vapply(authors, `slot`, character(1), "name")
@maurolepore
maurolepore / fgeo_sites.csv
Created May 16, 2018 01:29
forestgeo fgeo sites georeference latitude longitude from http://bit.ly/2IJisLO
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 41 columns, instead of 34. in line 1.
Site name,Alternate site name/ abbreviation,State/ Province,Country,Biogeographic zone,GCB#,Latitude,Longitude,Elevation-min,Elevation-max,Topographic relief,Location & Elevation notes,n geographically distinct plots,Area,Plot Dimensions,Plot Area & Dimensions notes,First ForestGEO census year,First census year,Year added to network,Publication(s) describing site/plot,Affiliated web links,Number of Species,Number of Trees,Species & Number of trees notes,Forest Description ,FAO ecozone,Dominant vegetation type(s),Dominant Soil order(s),Soil Notes,Koppen Climate zone,MAT,MAP,Natural disturbance regime,Natural disturbance notes,Past anthropogenic disturbances,Current anthropogenic disturbances,Anthropogenic disturbance notes,PI1,PI2,PI3,PI4
Amacayacu,,Amazonas,Colombia,Neotropic,42,-3.8091,-70.2678,,,,,1,25,500 x 500,,2006,,2006,"Arias Garcia et al., 2009",,1133,123790,,,Tropical rainforest,BE,Ult,Soil classification done by Turner: mainly Paleudults; underlying geology is the Pebas formation,Af,25.8,3215,Fl,inf
@maurolepore
maurolepore / tidy_tools.md
Last active May 16, 2018 14:00
tidy tools Hadtley Wickham workshop questions R

When should I force arguments passed into a closure from a function factory? Always? Sometimes? I what cases?

E.g. fgeo.base::keep_drop().

temps <- seq(-10, 50, 10)

for (i in seq_along(temps)) {
  
  if (temps[[i]] <= 0) {
    print("freezing")
  } else if (temps[[i]] <= 10) {
    print("cold")
 } else if (temps[[i]] &lt;= 20) {
@maurolepore
maurolepore / morgan.md
Created May 19, 2018 01:18
Morgan's law conditoin

@maurolepore
maurolepore / vars.md
Created May 19, 2018 01:30
common variable names adv-r advanced r hadley wickham advice good practice

@maurolepore
maurolepore / count_used_funs_by_package.md
Last active May 24, 2018 17:30
Count used functions by package, rev_dependency_usage, ropensci, runconf18

Based on code by Noam Ross (@noamross), developed during runconf18 (https://github.com/ropensci/unconf18)

#' Review dependency usage: Count used functions from external packages.
#' 
#' @inheritParams functionMap::map_r_package
#'
#' @return A dataframe.
#' @export
#'