{"id":15554880,"url":"https://github.com/patrickroocks/listcompr","last_synced_at":"2025-07-07T16:41:06.239Z","repository":{"id":56934555,"uuid":"326391415","full_name":"patrickroocks/listcompr","owner":"patrickroocks","description":"An R package for list comprehension","archived":false,"fork":false,"pushed_at":"2021-10-03T15:31:39.000Z","size":151,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T03:01:31.535Z","etag":null,"topics":["data-frames","list-comprehension","matrix","r","syntactic-sugar","vector"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickroocks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-03T11:30:41.000Z","updated_at":"2024-10-29T15:47:23.000Z","dependencies_parsed_at":"2022-08-21T00:40:33.066Z","dependency_job_id":null,"html_url":"https://github.com/patrickroocks/listcompr","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroocks%2Flistcompr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroocks%2Flistcompr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroocks%2Flistcompr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroocks%2Flistcompr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickroocks","download_url":"https://codeload.github.com/patrickroocks/listcompr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250504085,"owners_count":21441527,"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":["data-frames","list-comprehension","matrix","r","syntactic-sugar","vector"],"created_at":"2024-10-02T15:03:57.020Z","updated_at":"2025-04-23T19:48:42.076Z","avatar_url":"https://github.com/patrickroocks.png","language":"R","readme":"# listcompr\n\nThe **listcompr** package is a light-weight collection of functions for list comprehension. It is intended as “syntactic sugar” for R and it is inspired by the list comprehension capabilities from 'python'. Next to lists, similar structures like vectors (of numeric or character type), data frames, matrices, or named lists can be easily composed. The package may be used for the simple generation of small data sets for “textbook examples”, for unit tests of your R code, or for tiny mathematical tasks.\n\n## Installation\n\n[listcompr is on CRAN.](https://CRAN.R-project.org/package=listcompr) To install the latest version from CRAN, simply use:\n\n    install.packages(\"listcompr\")\n\nTo install and load the latest development version from this repository, execute the following in R:\n\n    install.packages(\"devtools\")\n    library(devtools)\n\n    install_github(\"patrickroocks/listcompr\", build_vignettes = TRUE)\n    library(listcompr)\n\n## Examples\n\n### Tiny examples\n\nWe show the basic functionality to compose lists, vectors and data frames.\nThe first argument for each generator function (`gen.list`, `gen.vector`, `gen.data.frame`, and `gen.matrix`) is a base expression, and the other arguments are variable ranges and conditions.\n\nFirst, we want to get a vector of all numbers in `1:10` which can be divided by 3 or 4:\n\n    gen.vector(i, i = 1:10, i %% 3 == 0 || i %% 4 == 0)\n    ## Returns: c(3, 4, 6, 8, 9)\n\nNext we want to compose a list of tuples `c(i, j)` where `i` and `j` are from `1:3` and` i \u003c= j` holds:\n\n    gen.list(c(i, j), i = 1:3, j = i:3)\n    ## Returns: list(c(1, 1), c(1, 2), c(2, 2), c(1, 3), c(2, 3), c(3, 3))\n\nThere is also a function to compose a data frame which expects a named vector as base expression.\nFor example we can easily sum up `1:i` while iterating over `i`:\n\n    gen.data.frame(c(a, sum = sum(1:a)), a = 1:10)\n\nThe first three lines of this data frame are:\n\n            a sum\n        1   1   1\n        2   2   3\n        3   3   6\n\n### Nested calculations and named lists\n\nIn **listcompr**, the list and vector compositions can be nested. \nWe create a vector containing all \"perfect numbers\" between 2 and 100, i.e., numbers where the sum of the divisors equals the number:\n\n    gen.vector(a, a = 2:100, a == sum(gen.vector(x, x = 1:(a-1), a %% x == 0)))\n    ## Returns: c(6, 28)\n\nThere are also functions to compose characters. For instance the package offers a function `gen.named.list`, where the first argument is the name (expressions in `{}`-brackets are substituted) of each list entry. The remaining arguments are the same as for `gen.list`. The following statement gives us all the divisors between 5 and 10:\n\n    gen.named.list('divisors_of_{a}', gen.vector(x, x = 1:(a-1), a %% x == 0), a = 5:10)\n    \nThe last list entry has the name `'divisors_of_10'` and the content `c(1, 2, 5)`.\n\n### More examples\n\nAfter installation of the package, run\n\n    vignette(\"introduction\", package = \"listcompr\")\n\nto see a vignette with some more examples.\n\n## Contact\n\nTo submit bugs or suggest improvements, feel free to [open a issue](https://github.com/patrickroocks/listcompr/issues) or write a mail to me: Patrick Roocks, mail@p-roocks.de\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroocks%2Flistcompr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickroocks%2Flistcompr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroocks%2Flistcompr/lists"}