tor

[R-package on CRAN] Import multiple datasets at once

https://github.com/maurolepore/tor

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.5%) to scientific vocabulary

Keywords

multiple-files r read tor
Last synced: 6 months ago · JSON representation

Repository

[R-package on CRAN] Import multiple datasets at once

Basic Info
Statistics
  • Stars: 19
  • Watchers: 1
  • Forks: 1
  • Open Issues: 4
  • Releases: 4
Topics
multiple-files r read tor
Created about 7 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog Contributing License Code of conduct Support

README.Rmd

---
output: github_document
editor_options: 
  chunk_output_type: console
---



```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# tor


[![CRAN status](https://www.r-pkg.org/badges/version/tor)](https://CRAN.R-project.org/package=tor)
[![Codecov test coverage](https://codecov.io/gh/maurolepore/tor/branch/main/graph/badge.svg)](https://app.codecov.io/gh/maurolepore/tor?branch=main)
[![R-CMD-check](https://github.com/maurolepore/tor/workflows/R-CMD-check/badge.svg)](https://github.com/maurolepore/tor/actions)
[![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)


__tor__ (_to-R_) helps you to import multiple files at once. For example:

* Run `list_rds()` to import all .csv files from your working directory into a list.
* Run `load_csv()` to import all .csv files from your working directory into your global environment.

## Installation

Install __tor__ from CRAN with:

```r
install.packages("tor")
```

Or install the development version from GitHub with:

``` r
# install.packages("devtools")
devtools::install_github("maurolepore/tor")
```

## Example

```{r}
library(tor)

withr::local_options(readr.show_col_types = FALSE)
```

### `list_*()`: Import multiple files from a directory into a list

All functions default to importing files from the working directory.

```{r}
dir()

list_csv()
```

Often you will specify a `path` to read from.

```{r}
# Helpes create paths to examples
tor_example()

(path_rds <- tor_example("rds"))
dir(path_rds)

list_rds(path_rds)
```

You may read all files with a particular extension.

```{r}
path_mixed <- tor_example("mixed")
dir(path_mixed)

list_rdata(path_mixed)
```

Or you may read specific files matching a pattern.

```{r}
list_rdata(path_mixed, regexp = "[.]RData", ignore.case = FALSE)
```

`list_any()` is the most flexible function. You supply the function to read with.

```{r}
(path_csv <- tor_example("csv"))
dir(path_csv)

list_any(path_csv, read.csv)
```

It understands lambda functions and formulas (powered by [__rlang__](https://rlang.r-lib.org/)).

```{r}
# Use the pipe (%>%)
library(magrittr)

(path_rdata <- tor_example("rdata"))
dir(path_rdata)

path_rdata %>%
  list_any(function(x) get(load(x)))

# Same
path_rdata %>%
  list_any(~ get(load(.x)))
```

Pass additional arguments via `...` or inside the lambda function.

```{r}
path_csv %>%
  list_any(readr::read_csv, skip = 1)

path_csv %>%
  list_any(~ read.csv(., stringsAsFactors = FALSE))
```

It also provides the arguments `regexp`, `ignore.case`, and `invert` to pick specific files in a directory (powered by [__fs__](https://fs.r-lib.org/)).

```{r}
path_mixed <- tor_example("mixed")
dir(path_mixed)

path_mixed %>%
  list_any(~ get(load(.)), "[.]Rdata$", ignore.case = TRUE)

path_mixed %>%
  list_any(~ get(load(.)), regexp = "[.]csv$", invert = TRUE)
```

### `load_*()`: Load multiple files from a directory into an environment

All functions default to importing files from the working directory and into the global environment.

```{r}
# The working directory contains .csv files
dir()

load_csv()

# Each file is now available as a dataframe in the global environment
csv1
csv2

rm(list = ls())
```

You may import files from a specific `path`.

```{r}
(path_mixed <- tor_example("mixed"))
dir(path_mixed)

load_rdata(path_mixed)

ls()
rda
```

You may import files into a specific `envir`onment.

```{r}
e <- new.env()
ls(e)

load_rdata(path_mixed, envir = e)

ls(e)
```

For more flexibility use `load_any()` with a function able to read one file of the format you want to import.

```{r}
dir()

load_any(".", .f = readr::read_csv, regexp = "[.]csv$")

# The data is now available in the global environment
csv1
csv2
```

# Related projects

Two 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).

## Information

* [Getting help](https://maurolepore.github.io/tor/SUPPORT.html).
* [Contributing](https://maurolepore.github.io/tor/CONTRIBUTING.html).
* [Contributor Code of Conduct](https://maurolepore.github.io/tor/CODE_OF_CONDUCT.html).

Owner

  • Name: Mauro Lepore
  • Login: maurolepore
  • Kind: user
  • Location: Amsterdam, Netherlands
  • Company: https://theiafinance.org/

I solve problems systematically -- with data, research, software, and teaching

GitHub Events

Total
Last Year

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 134
  • Total Committers: 1
  • Avg Commits per committer: 134.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mauro Lepore m****e@g****m 134

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 14
  • Total pull requests: 37
  • Average time to close issues: 17 days
  • Average time to close pull requests: 11 days
  • Total issue authors: 3
  • Total pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.11
  • Merged pull requests: 31
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 7
  • Average time to close issues: 34 minutes
  • Average time to close pull requests: 14 minutes
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.14
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • maurolepore (12)
  • MilesMcBain (1)
  • KyleHaynes (1)
Pull Request Authors
  • maurolepore (44)
Top Labels
Issue Labels
feature (5) enhancement (2) docs (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 147 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 4
  • Total maintainers: 1
cran.r-project.org: tor

Import Multiple Files From a Single Directory at Once

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 147 Last month
Rankings
Stargazers count: 12.2%
Forks count: 21.0%
Dependent repos count: 23.9%
Dependent packages count: 28.8%
Average: 29.5%
Downloads: 61.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.2 depends
  • fs * imports
  • readr * imports
  • rlang * imports
  • tibble * imports
  • covr * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • spelling * suggests
  • testthat * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.5.0 composite
  • actions/checkout v4 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v1 composite
  • actions/checkout master composite
  • r-lib/actions/pr-fetch master composite
  • r-lib/actions/pr-push master composite
  • r-lib/actions/setup-r master composite
.github/workflows/rhub.yaml actions
  • r-hub/actions/checkout v1 composite
  • r-hub/actions/platform-info v1 composite
  • r-hub/actions/run-check v1 composite
  • r-hub/actions/setup v1 composite
  • r-hub/actions/setup-deps v1 composite
  • r-hub/actions/setup-r v1 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v4 composite
  • actions/upload-artifact v4 composite
  • codecov/codecov-action v4 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite