# A custom error with base
f <- function() {
message <- paste(c("Oh no", "Messed up", "Need a hint?"), collapse = "\n")
# Construct a custom class via `errorCondition()`
stop(errorCondition(message, class = "my_error"))
}
# How it prints
f()
library(shiny)
ui <- fluidPage(
textInput("name", "What's your name?"),
textOutput("greeting")
)
server <- function(input, output, session) {
output$greeting <- renderText(paste("Hello", input$name))
#' Calculate the nevitable Policy Response (IPR)
#'
#' @param plan_x What is this?
#' @param scen_start What is this?
#' @param scen_end What is this?
#' @param year_x What is this?
#' @param year_start What is this?
#' @param year_end What is this?
#'
library(dplyr, warn.conflicts = FALSE)
scenarioSelector::scenarios %>%
select(variable, unit, technology) %>%
distinct()
#> # A tibble: 29 x 3
#> variable unit technology
#> <chr> <chr> <chr>
#> 1 emission_factor tonnes of CO2 per tonne of cement <NA>
# 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)
Original post https://github.com/2DegreesInvesting/r2dii.analysis/issues/318#issuecomment-868408729
--
Thanks @jdhoffa for such a complete explanation.
@maurolepore the ssh key that I generate are not recognized by github (and have not the good format) so I still can push my commit here but I'll drop you the two files with the commit message associated:
1st change in join_ald_scenario:
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"