README.md

mappers

R build
status

The goal of mapping is to provide callable key-value tables that can be manipulated as {vctrs}.

Installation

install.packages("jameelalsalam/mapping")

Example

This is a basic example which shows you how to solve a common problem:

library(mapping)
suppressPackageStartupMessages(library(tidyverse))
## basic example code

countries <- c("FR", "GR", "IT")
capitals  <- c("Paris", "Berlin", "Rome")

eu_caps <- mapping(countries, capitals)

Display:

eu_caps
#> <mapping[3]>
#> [1] FR->Paris  GR->Berlin IT->Rome

Apply the mapping:

eu_caps(countries)
#> [1] "Paris"  "Berlin" "Rome"

Use in tidyverse pipelines:

tibble(
  countries = c("FR", "FR", "IT", "GR")
) %>%
  mutate(capitals = eu_caps(countries))
#> # A tibble: 4 x 2
#>   countries capitals
#>   <chr>     <chr>   
#> 1 FR        Paris   
#> 2 FR        Paris   
#> 3 IT        Rome    
#> 4 GR        Berlin

The keys, values, and keyvalues can be retrieved, queried, and modified:

In future, it will go inside a tibble:

# data.frame(
#   kv = eu_caps
# )

Compose mappings:



jameelalsalam/mapping documentation built on May 31, 2020, 2:39 p.m.