{"id":23099306,"url":"https://github.com/maurolepore/tor","last_synced_at":"2025-08-16T13:31:03.863Z","repository":{"id":46341856,"uuid":"163967682","full_name":"maurolepore/tor","owner":"maurolepore","description":"[R-package on CRAN] Import multiple datasets at once","archived":false,"fork":false,"pushed_at":"2024-07-14T23:48:36.000Z","size":1627,"stargazers_count":19,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-28T15:41:08.883Z","etag":null,"topics":["multiple-files","r","read","tor"],"latest_commit_sha":null,"homepage":"https://maurolepore.github.io/tor/","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/maurolepore.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-03T12:02:19.000Z","updated_at":"2024-07-14T23:47:06.000Z","dependencies_parsed_at":"2022-09-19T05:30:56.380Z","dependency_job_id":null,"html_url":"https://github.com/maurolepore/tor","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maurolepore%2Ftor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maurolepore%2Ftor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maurolepore%2Ftor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maurolepore%2Ftor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maurolepore","download_url":"https://codeload.github.com/maurolepore/tor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230038869,"owners_count":18163319,"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":["multiple-files","r","read","tor"],"created_at":"2024-12-16T23:18:50.237Z","updated_at":"2024-12-16T23:18:50.825Z","avatar_url":"https://github.com/maurolepore.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\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(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# tor\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/tor)](https://CRAN.R-project.org/package=tor)\n[![Codecov test coverage](https://codecov.io/gh/maurolepore/tor/branch/main/graph/badge.svg)](https://app.codecov.io/gh/maurolepore/tor?branch=main)\n[![R-CMD-check](https://github.com/maurolepore/tor/workflows/R-CMD-check/badge.svg)](https://github.com/maurolepore/tor/actions)\n[![R-CMD-check](https://github.com/maurolepore/tor/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/maurolepore/tor/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\n__tor__ (_to-R_) helps you to import multiple files at once. For example:\n\n* Run `list_rds()` to import all .csv files from your working directory into a list.\n* Run `load_csv()` to import all .csv files from your working directory into your global environment.\n\n## Installation\n\nInstall __tor__ from CRAN with:\n\n```r\ninstall.packages(\"tor\")\n```\n\nOr install the development version from GitHub with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"maurolepore/tor\")\n```\n\n## Example\n\n```{r}\nlibrary(tor)\n\nwithr::local_options(readr.show_col_types = FALSE)\n```\n\n### `list_*()`: Import multiple files from a directory into a list\n\nAll functions default to importing files from the working directory.\n\n```{r}\ndir()\n\nlist_csv()\n```\n\nOften you will specify a `path` to read from.\n\n```{r}\n# Helpes create paths to examples\ntor_example()\n\n(path_rds \u003c- tor_example(\"rds\"))\ndir(path_rds)\n\nlist_rds(path_rds)\n```\n\nYou may read all files with a particular extension.\n\n```{r}\npath_mixed \u003c- tor_example(\"mixed\")\ndir(path_mixed)\n\nlist_rdata(path_mixed)\n```\n\nOr you may read specific files matching a pattern.\n\n```{r}\nlist_rdata(path_mixed, regexp = \"[.]RData\", ignore.case = FALSE)\n```\n\n`list_any()` is the most flexible function. You supply the function to read with.\n\n```{r}\n(path_csv \u003c- tor_example(\"csv\"))\ndir(path_csv)\n\nlist_any(path_csv, read.csv)\n```\n\nIt understands lambda functions and formulas (powered by [__rlang__](https://rlang.r-lib.org/)).\n\n```{r}\n# Use the pipe (%\u003e%)\nlibrary(magrittr)\n\n(path_rdata \u003c- tor_example(\"rdata\"))\ndir(path_rdata)\n\npath_rdata %\u003e%\n  list_any(function(x) get(load(x)))\n\n# Same\npath_rdata %\u003e%\n  list_any(~ get(load(.x)))\n```\n\nPass additional arguments via `...` or inside the lambda function.\n\n```{r}\npath_csv %\u003e%\n  list_any(readr::read_csv, skip = 1)\n\npath_csv %\u003e%\n  list_any(~ read.csv(., stringsAsFactors = FALSE))\n```\n\nIt also provides the arguments `regexp`, `ignore.case`, and `invert` to pick specific files in a directory (powered by [__fs__](https://fs.r-lib.org/)).\n\n```{r}\npath_mixed \u003c- tor_example(\"mixed\")\ndir(path_mixed)\n\npath_mixed %\u003e%\n  list_any(~ get(load(.)), \"[.]Rdata$\", ignore.case = TRUE)\n\npath_mixed %\u003e%\n  list_any(~ get(load(.)), regexp = \"[.]csv$\", invert = TRUE)\n```\n\n### `load_*()`: Load multiple files from a directory into an environment\n\nAll functions default to importing files from the working directory and into the global environment.\n\n```{r}\n# The working directory contains .csv files\ndir()\n\nload_csv()\n\n# Each file is now available as a dataframe in the global environment\ncsv1\ncsv2\n\nrm(list = ls())\n```\n\nYou may import files from a specific `path`.\n\n```{r}\n(path_mixed \u003c- tor_example(\"mixed\"))\ndir(path_mixed)\n\nload_rdata(path_mixed)\n\nls()\nrda\n```\n\nYou may import files into a specific `envir`onment.\n\n```{r}\ne \u003c- new.env()\nls(e)\n\nload_rdata(path_mixed, envir = e)\n\nls(e)\n```\n\nFor more flexibility use `load_any()` with a function able to read one file of the format you want to import.\n\n```{r}\ndir()\n\nload_any(\".\", .f = readr::read_csv, regexp = \"[.]csv$\")\n\n# The data is now available in the global environment\ncsv1\ncsv2\n```\n\n# Related projects\n\nTwo great packages to read and write data are [__rio__](https://CRAN.R-project.org/package=rio) and [__io__](https://CRAN.R-project.org/package=io).\n\n## Information\n\n* [Getting help](https://maurolepore.github.io/tor/SUPPORT.html).\n* [Contributing](https://maurolepore.github.io/tor/CONTRIBUTING.html).\n* [Contributor Code of Conduct](https://maurolepore.github.io/tor/CODE_OF_CONDUCT.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaurolepore%2Ftor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaurolepore%2Ftor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaurolepore%2Ftor/lists"}