Skip to content

Instantly share code, notes, and snippets.

View maurolepore's full-sized avatar

Mauro Lepore maurolepore

View GitHub Profile
# Scenario data source:
# https://github.com/2DegreesInvesting/CapitalMarketsPlatform/blob/master/data/scenario_data.rds
# commit: a72c75b

library(tidyverse)
set.seed(123)

raw <- readr::read_rds("data-raw/scenario_data.rds")
# if (interactive()) glimpse(raw)
library(dplyr, warn.conflicts = FALSE)
devtools::load_all(quiet = TRUE)

# Helper?
order_lines <- function(data, order) {
  data %>% 
    mutate(metric = factor(.data$metric, levels = order)) %>% 
    arrange(.data$metric)
}
library(testthat)

# R/utils.R
source_all <- function(paths, ...) {
  lapply(paths, source, ...)
  invisible(paths)
}

# test/testthat/test-utils.R
library(ggplot2, warn.conflicts = FALSE)

ggplot(iris) + 
  geom_histogram(aes(Sepal.Length, fill = Species), bins = 15, alpha = 0.5)

Created on 2021-05-03 by the reprex package (v2.0.0)

library(dplyr, warn.conflicts = FALSE)
library(testthat, warn.conflicts = FALSE)
library(r2dii.match)
library(r2dii.analysis)

.production <- c(1, 10)
.year <- 2022
.company <- "toyota motor corp"
.sector <- "automotive"
library(tidyverse, warn.conflicts = FALSE)
library(glue, warn.conflicts = FALSE)
library(fs)
library(vroom)

# Your data is too big to save on GitHub as a single file
big_data <- tibble(
  x = rnorm(10)
)
# The error you show seems to come from data.frame(), not tibble(). 
data.frame <- function(...) {
  base::data.frame(..., stringsAsFactors = FALSE)
}

# Notice this is the exact same error you show
data.frame(x = 1:3, y = 1:4)
#> Error in base::data.frame(..., stringsAsFactors = FALSE): arguments imply differing number of rows: 3, 4
library(tidyverse, warn.conflicts = FALSE)
library(fs)
library(vroom)
library(stringdist)
#> 
#> Attaching package: 'stringdist'
#> The following object is masked from 'package:tidyr':
#> 
#&gt; extract
# Commit: effe46ff (HEAD -> master, origin/master, origin/HEAD) changed we to wE in weight_allom : tests pass again

goodpractice::gp()
#> Preparing: covr
#> Preparing: cyclocomp
#> 
#>      checking for file ‘/tmp/Rtmp7oUrAk/remotes56056ad46178/allodb/DESCRIPTION’ ...  ✓  checking for file ‘/tmp/Rtmp7oUrAk/remotes56056ad46178/allodb/DESCRIPTION’
#>   ─  preparing ‘allodb’: