{"id":13857899,"url":"https://github.com/mkearney/dapr","last_synced_at":"2025-08-21T20:26:19.161Z","repository":{"id":56936892,"uuid":"153846249","full_name":"mkearney/dapr","owner":"mkearney","description":"☝🏼👉🏼👇🏼👈🏼 Dependency-free purrr-like apply/map/iterate functions","archived":false,"fork":false,"pushed_at":"2019-06-28T18:49:36.000Z","size":1022,"stargazers_count":52,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T05:41:55.706Z","etag":null,"topics":["for-loops","functional-programming","iterator","r","r-package","rstats"],"latest_commit_sha":null,"homepage":"https://dapr.mikewk.com","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkearney.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-19T21:56:59.000Z","updated_at":"2025-03-22T10:59:34.000Z","dependencies_parsed_at":"2022-08-21T01:10:11.376Z","dependency_job_id":null,"html_url":"https://github.com/mkearney/dapr","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fdapr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fdapr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fdapr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkearney%2Fdapr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkearney","download_url":"https://codeload.github.com/mkearney/dapr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557844,"owners_count":21124165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["for-loops","functional-programming","iterator","r","r-package","rstats"],"created_at":"2024-08-05T03:01:50.066Z","updated_at":"2025-04-12T10:51:08.684Z","avatar_url":"https://github.com/mkearney.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(echo = TRUE, collapse = TRUE, comment = \"#\u003e\")\nlibrary(dapr)\n```\n# dapr \u003cimg src=\"man/figures/logo.png\" width=\"160px\" align=\"right\" /\u003e\n\n[![Build status](https://travis-ci.org/mkearney/dapr.svg?branch=master)](https://travis-ci.org/mkearney/dapr)\n[![CRAN status](https://www.r-pkg.org/badges/version/dapr)](https://cran.r-project.org/package=dapr)\n[![Coverage Status](https://codecov.io/gh/mkearney/dapr/branch/master/graph/badge.svg)](https://codecov.io/gh/mkearney/dapr?branch=master)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2528504.svg)](https://doi.org/10.5281/zenodo.2528504)\n![Downloads](https://cranlogs.r-pkg.org/badges/dapr?color=yellowgreen)\n![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/dapr?color=dd69b4)\n[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)\n\nDependency-free purrr-like apply/map/iterate functions\n\n## Installation\n\nInstall the development version from Github with:\n\n``` r\n## install remotes pkg if not already\nif (!requireNamespace(\"remotes\", quietly = TRUE)) {\n  install.packages(\"remotes\")\n}\n\n## install from github\nremotes::install_github(\"mkearney/dapr\")\n```\n\n## {dapr} vs. {base} \u0026 {purrr}?\n**{dapr}** provides the ease and consistency of [**{purrr}**](https://purrr.tidyverse.org),\n(see also: simple benchmark results plot below) including use of `~` and `.x`,\nwithout all the dependencies. In other words, use **{dapr}** when you want a \npurrr-like experience but you need a lightweight solution.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"tools/readme/benchmark.png\"/\u003e\n\u003c/p\u003e\n\n## Use\n\nFunction names use the convention `*ap()` where **`*`** is the first letter of output data type.\n\n+ \u003ccode\u003e\u003cspan style=\"font-weight:bold;text-decoration:underline\"\u003ev\u003c/span\u003eap\u003c/code\u003e for **vectors**\n+ \u003ccode\u003e\u003cspan style=\"font-weight:bold;text-decoration:underline\"\u003el\u003c/span\u003eap\u003c/code\u003e for **lists**\n+ \u003ccode\u003e\u003cspan style=\"font-weight:bold;text-decoration:underline\"\u003ed\u003c/span\u003eap\u003c/code\u003e for **data frames**\n\nCommon inputs:\n\n+ `.data` Input object–numeric, character, list, data frame, etc.–over which elements will be iterated. If matrix or data frame, each column will be treated as the elements which are to be iterated over.\n+ `.f` Function to apply to each element of input object. This can be written as a single function name e.g., `mean`, a formula-like function call where `.x` is assumed to be the iterated over element of input data e.g., `~ mean(.x)`, or an in-line function definition e.g., `function(x) mean(x)`.\n\n### Vectors\n\nFunctions that apply expressions to input data objects and return atomic vectors\ne.g., numeric (double), character, logical.\n\n+ **`vap_dbl()`** Iterate and return **numeric** vector.\n+ **`vap_int()`** Iterate and return **integer** vector.\n+ **`vap_lgl()`** Iterate and return **logical** vector.\n+ **`vap_chr()`** Iterate and return **character** vector.\n\n```{r}\n## create data\nset.seed(2018)\nd \u003c- replicate(5, rnorm(10), simplify = FALSE)\ne \u003c- replicate(5, sample(letters, 10), simplify = FALSE)\n\n## numeric\nvap_dbl(d, ~ mean(.x))\n\n## integer\nvap_int(d, length)\n\n## logical\nvap_lgl(d, ~ max(.x) \u003e 3)\n\n## character\nvap_chr(e, paste, collapse = \"\")\n```\n\n### Lists\n\nFunction(s) that apply expressions to input data objects and return lists.\n\n+ **`lap()`** Iterate and return a **list** vector.\n\n```{r}\n## list of strings\nlap(e[1:2], ~ paste0(.x, \".\"))\n```\n\n+ **`ilap()`** Iterate over sequence length `.i` (instead of `.x`) and return a **list** vector.\n\n```{r}\n## list of strings\nilap(1:4, ~ paste0(letters[.i], rev(LETTERS)[.i]))\n```\n\n### Data frames\n\nFunctions that apply expressions to input data objects and return data frames.\n\n+ **`dap*()`** Iterate and return a **data frame**\n   - **`dapc()`** Iterate over **columns**\n   - **`dapr()`** Iterate over **rows**\n+ **`dap*_if()`** Conditionally iterate\n   - **`dapc_if()`** Conditionally iterate over **columns**\n   - **`dapr_if()`** Conditionally iterate over **rows**\n\n```{r}\n## some data\nd \u003c- data.frame(\n  a = letters[1:3],\n  b = rnorm(3),\n  c = rnorm(3),\n  stringsAsFactors = FALSE\n)\n\n## column explicit (same as dap)\ndapc(d[-1], ~ round(.x, 2))\n\n## rows\ndapr(d[-1], round, 3)\n\n## conditional COLUMNS\ndapc_if(d, is.numeric, ~ round(.x, 4))\n\n## conditional ROWS\ndapr_if(d[-1], ~ sum(.x) \u003e= -.7, ~ round(.x, 0))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkearney%2Fdapr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkearney%2Fdapr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkearney%2Fdapr/lists"}