├── .Rbuildignore
├── .editorconfig
├── .github
├── .gitignore
└── workflows
│ ├── R-CMD-check.yaml
│ ├── pkgdown.yml
│ └── test-coverage.yaml
├── .gitignore
├── CONTRIBUTING.md
├── DESCRIPTION
├── Makefile
├── NAMESPACE
├── NEWS.md
├── R
├── characterize.R
├── compression.R
├── convert.R
├── export.R
├── export_list.R
├── export_methods.R
├── extensions.R
├── gather_attrs.R
├── import.R
├── import_list.R
├── import_methods.R
├── onLoad.R
├── remote_to_local.R
├── rio.R
├── set_class.R
├── standardize_attributes.R
├── suggestions.R
├── sysdata.rda
└── utils.R
├── README.Rmd
├── README.md
├── _pkgdown.yml
├── codecov.yml
├── data-raw
├── convert.R
├── obsolete
│ ├── arg_reconcile.R
│ ├── is_file_text.R
│ ├── old_logo
│ │ ├── logo.png
│ │ └── logo.svg
│ ├── test_arg_reconcile.R
│ └── test_is_file_text.R
├── readme.md
└── single.json
├── inst
└── CITATION
├── man
├── characterize.Rd
├── convert.Rd
├── export.Rd
├── export_list.Rd
├── figures
│ ├── logo.png
│ └── logo.svg
├── gather_attrs.Rd
├── get_info.Rd
├── import.Rd
├── import_list.Rd
├── install_formats.Rd
└── rio.Rd
├── po
└── R-rio.pot
├── rio.Rproj
├── starwars.csv
├── starwars.xlsx
├── tests
├── testdata
│ ├── br-in-header.html
│ ├── br-in-td.html
│ ├── example.csvy
│ ├── iris.xls
│ ├── iris_no_extension_xls
│ ├── mtcars.ods
│ ├── noheader.csv
│ ├── th-as-row-element.html
│ ├── two-tbody.html
│ └── twotables.html
├── testthat.R
└── testthat
│ ├── test_characterize.R
│ ├── test_check_file.R
│ ├── test_compress.R
│ ├── test_convert.R
│ ├── test_create_outfiles.R
│ ├── test_errors.R
│ ├── test_export_corner_cases.R
│ ├── test_export_list.R
│ ├── test_extensions.R
│ ├── test_format_R.R
│ ├── test_format_arff.R
│ ├── test_format_csv.R
│ ├── test_format_csvy.R
│ ├── test_format_dbf.R
│ ├── test_format_dif.R
│ ├── test_format_dta.R
│ ├── test_format_eviews.R
│ ├── test_format_external_packages.R
│ ├── test_format_feather.R
│ ├── test_format_fortran.R
│ ├── test_format_fst.R
│ ├── test_format_fwf.R
│ ├── test_format_html.R
│ ├── test_format_json.R
│ ├── test_format_matlab.R
│ ├── test_format_mtp.R
│ ├── test_format_ods.R
│ ├── test_format_parquet.R
│ ├── test_format_psv.R
│ ├── test_format_pzfx.R
│ ├── test_format_qs.R
│ ├── test_format_rdata.R
│ ├── test_format_rds.R
│ ├── test_format_rec.R
│ ├── test_format_sas.R
│ ├── test_format_sav.R
│ ├── test_format_syd.R
│ ├── test_format_tsv.R
│ ├── test_format_xls.R
│ ├── test_format_xml.R
│ ├── test_format_yml.R
│ ├── test_gather_attrs.R
│ ├── test_guess.R
│ ├── test_identical.R
│ ├── test_import_list.R
│ ├── test_mapping.R
│ ├── test_matrix.R
│ ├── test_remote.R
│ ├── test_set_class.R
│ ├── test_suggestions.R
│ └── test_trust.R
└── vignettes
├── .gitignore
├── extension.Rmd
├── labelled.Rmd
├── philosophy.Rmd
├── remap.Rmd
└── rio.Rmd
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^pkgdown/.+$
2 | .github/*
3 | ^\.travis\.yml$
4 | ^appveyor\.yml$
5 | ^travis-tool\.sh$
6 | ^Makefile$
7 | ^README\.Rmd$
8 | ^README\.html$
9 | ^README_files$
10 | ^README_files/.+$
11 | ^CONTRIBUTING\.md$
12 | ^inst/standarderrors\.pdf$
13 | ^figure$
14 | ^figure/.+$
15 | ^man-roxygen$
16 | ^man-roxygen/.+$
17 | ^revdep$
18 | ^revdep/.+$
19 | ^cache/.+$
20 | ^docs$
21 | ^docs/.+$
22 | ^ignore$
23 | ^inst/doc/.+\.log$
24 | ^vignettes/figure$
25 | ^vignettes/figure/.+$
26 | ^vignettes/.+\.aux$
27 | ^vignettes/.+\.bbl$
28 | ^vignettes/.+\.blg$
29 | ^vignettes/.+\.dvi$
30 | ^vignettes/.+\.log$
31 | ^vignettes/.+\.out$
32 | ^vignettes/.+\.pdf$
33 | ^vignettes/.+\.sty$
34 | ^vignettes/.+\.tex$
35 | ^data-raw$
36 | ^.*\.Rproj$
37 | ^\.Rproj\.user$
38 | ^\.github$
39 | ^\.editorconfig$
40 | ^starwars.xlsx$
41 | ^starwars.csv$
42 | ^codecov\.yml$
43 | ^cran-comments\.md$
44 | ^CRAN-SUBMISSION$
45 | ^codemeta\.json$
46 | ^_pkgdown\.yml$
47 | ^pkgdown$
48 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 |
4 | [*]
5 | charset = utf8
6 | end_of_line = lf
7 | insert_final_newline = true
8 | indent_style = space
9 |
10 |
11 | [*.{r,R,rmd,Rmd,cpp}]
12 | indent_size = 4
13 | trim_trailing_whitespace = true
14 |
15 | [Makefile]
16 | indent_style = tab
17 |
--------------------------------------------------------------------------------
/.github/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/.github/workflows/R-CMD-check.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | pull_request:
7 | branches: [main, master]
8 |
9 | name: R-CMD-check
10 |
11 | jobs:
12 | R-CMD-check:
13 | runs-on: ${{ matrix.config.os }}
14 |
15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }})
16 |
17 | strategy:
18 | fail-fast: false
19 | matrix:
20 | config:
21 | - {os: macos-latest, r: 'release'}
22 | - {os: windows-latest, r: 'release'}
23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
24 | - {os: ubuntu-latest, r: 'release'}
25 | - {os: ubuntu-latest, r: 'oldrel-1'}
26 | - {os: ubuntu-latest, r: 'oldrel-2'}
27 | - {os: ubuntu-latest, r: 'oldrel-3'}
28 |
29 | env:
30 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
31 | R_KEEP_PKG_SOURCE: yes
32 |
33 | steps:
34 | - uses: actions/checkout@v3
35 |
36 | - uses: r-lib/actions/setup-pandoc@v2
37 |
38 | - uses: r-lib/actions/setup-r@v2
39 | with:
40 | r-version: ${{ matrix.config.r }}
41 | http-user-agent: ${{ matrix.config.http-user-agent }}
42 | use-public-rspm: true
43 |
44 | - uses: r-lib/actions/setup-r-dependencies@v2
45 | with:
46 | extra-packages: any::rcmdcheck, arrow=?ignore-before-r=4.0.0
47 | needs: check
48 |
49 | - uses: r-lib/actions/check-r-package@v2
50 | with:
51 | upload-snapshots: true
52 |
--------------------------------------------------------------------------------
/.github/workflows/pkgdown.yml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | # pull_request:
7 | # branches: [main, master]
8 | release:
9 | types: [published]
10 | workflow_dispatch:
11 |
12 | name: pkgdown
13 |
14 | jobs:
15 | pkgdown:
16 | runs-on: ubuntu-latest
17 | # Only restrict concurrency for non-PR jobs
18 | concurrency:
19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
20 | env:
21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
22 | permissions:
23 | contents: write
24 | steps:
25 | - uses: actions/checkout@v3
26 |
27 | - uses: r-lib/actions/setup-pandoc@v2
28 |
29 | - uses: r-lib/actions/setup-r@v2
30 | with:
31 | use-public-rspm: true
32 |
33 | - uses: r-lib/actions/setup-r-dependencies@v2
34 | with:
35 | extra-packages: any::pkgdown, local::.
36 | needs: website
37 |
38 | - name: Build site
39 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
40 | shell: Rscript {0}
41 |
42 | - name: Deploy to GitHub pages 🚀
43 | if: github.event_name != 'pull_request'
44 | uses: JamesIves/github-pages-deploy-action@v4.4.1
45 | with:
46 | clean: false
47 | branch: gh-pages
48 | folder: docs
49 |
--------------------------------------------------------------------------------
/.github/workflows/test-coverage.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | pull_request:
7 | branches: [main, master]
8 |
9 | name: test-coverage
10 |
11 | jobs:
12 | test-coverage:
13 | runs-on: ubuntu-latest
14 | env:
15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
16 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
17 |
18 | steps:
19 | - uses: actions/checkout@v3
20 |
21 | - uses: r-lib/actions/setup-r@v2
22 | with:
23 | use-public-rspm: true
24 |
25 | - uses: r-lib/actions/setup-r-dependencies@v2
26 | with:
27 | extra-packages: any::covr
28 | needs: coverage
29 |
30 | - name: Test coverage
31 | run: |
32 | covr::codecov(
33 | quiet = FALSE,
34 | clean = FALSE,
35 | install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
36 | )
37 | shell: Rscript {0}
38 |
39 | - name: Show testthat output
40 | if: always()
41 | run: |
42 | ## --------------------------------------------------------------------
43 | find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
44 | shell: bash
45 |
46 | - name: Upload test results
47 | if: failure()
48 | uses: actions/upload-artifact@v3
49 | with:
50 | name: coverage-test-failures
51 | path: ${{ runner.temp }}/package
52 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 | .Rhistory
3 | .Rproj.user
4 | revdep/*
5 | README.html
6 | inst/doc
7 | docs
8 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributions to **rio** are welcome from anyone and are best sent as pull requests on [the GitHub repository](https://github.com/gesistsa/rio/). This page provides some instructions to potential contributors about how to add to the package.
2 |
3 | 1. Contributions can be submitted as [a pull request](https://help.github.com/articles/creating-a-pull-request/) on GitHub by forking or cloning the [repo](https://github.com/gesistsa/rio/), making changes and submitting the pull request.
4 |
5 | 2. Pull requests should involve only one commit per substantive change. This means if you change multiple files (e.g., code and documentation), these changes should be committed together. If you don't know how to do this (e.g., you are making changes in the GitHub web interface) just submit anyway and the maintainer will clean things up.
6 |
7 | 3. All contributions must be submitted consistent with the package license ([GPL-2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)).
8 |
9 | 4. All contributions need to be noted in the `Authors@R` field in the [DESCRIPTION](https://github.com/gesistsa/rio/blob/master/DESCRIPTION). Just follow the format of the existing entries to add your name (and, optionally, email address). Substantial contributions should also be noted in [`inst/CITATION`](https://github.com/gesistsa/rio/blob/master/inst/CITATION).
10 |
11 | 5. This package uses royxgen code and documentation markup, so changes should be made to roxygen comments in the source code `.R` files. If changes are made, roxygen needs to be run. The easiest way to do this is a command line call to: `Rscript -e devtools::document()`. Please resolve any roxygen errors before submitting a pull request.
12 |
13 | 6. Please run `R CMD BUILD rio` and `R CMD CHECK rio_VERSION.tar.gz` before submitting the pull request to check for any errors.
14 |
15 | Some specific types of changes that you might make are:
16 |
17 | 1. Documentation-only changes (e.g., to Rd files, README, vignettes). This is great! All contributions are welcome.
18 |
19 | 2. Addition of new file format imports or exports. This is also great! Some advice:
20 |
21 | - Import is based on S3 dispatch to functions of the form `.import.rio_FORMAT()`. Export works the same, but with `.export.rio_FORMAT()`. New import/export methods should take this form. There's no need to change the body of the `import()` or `export()` functions; S3 will take care of dispatch. All `.import()` methods must accept a `file` and `which` argument: `file` represents the path to the file and `which` can be used to extract sheets or files from multi-object files (e.g., zip, Excel workbooks, etc.). `.export()` methods take two arguments: `file` and `x`, where `file` is the path to the file and `x` is the data frame being exported. Most of the work of import and export methods involves mapping these arguments to their corresponding argument names in the various underlying packages. See the Vignette: `remap`.
22 |
23 | - The S3 methods should be documented in [NAMESPACE](https://github.com/gesistsa/rio/blob/master/NAMESPACE) using `S3method()`, which is handled automatically by roxygen markup in the source code.
24 | - Any new format support needs to be documented in each of the following places: [README.Rmd](https://github.com/gesistsa/rio/blob/master/README.Rmd), [the vignette](https://github.com/gesistsa/rio/blob/master/vignettes/rio.Rmd), and the appropriate Rd file in [`/man`](https://github.com/gesistsa/rio/tree/master/man).
25 |
26 | - New formats or new options for handling formats should have a test added in [`/tests/testthat`](https://github.com/gesistsa/rio/tree/master/tests/testthat) called `test_format_FORMAT.R` that completely covers the function's behavior. This may require adding an example file to [`inst/examples`](https://github.com/gesistsa/rio/tree/master/inst/examples) (e.g., for testing `import()`).
27 |
28 | 3. Changes requiring a new package dependency should be discussed on the GitHub issues page before submitting a pull request.
29 |
30 | 4. Message translations. These are very appreciated! The format is a pain, but if you're doing this I'm assuming you're already familiar with it.
31 |
32 | Any questions you have can be opened as GitHub issues.
33 |
34 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: rio
2 | Type: Package
3 | Title: A Swiss-Army Knife for Data I/O
4 | Version: 1.2.4
5 | Authors@R: c(person("Jason", "Becker", role = "aut", email = "jason@jbecker.co"),
6 | person("Chung-hong", "Chan", role = c("aut", "cre"), email = "chainsawtiney@gmail.com",
7 | comment = c(ORCID = "0000-0002-6232-7530")),
8 | person("David", "Schoch", email = "david@schochastics.net", role = c("aut"),
9 | comment = c(ORCID = "0000-0003-2952-4812")),
10 | person("Geoffrey CH", "Chan", role = "ctb", email = "gefchchan@gmail.com"),
11 | person("Thomas J.", "Leeper",
12 | role = "aut",
13 | email = "thosjleeper@gmail.com",
14 | comment = c(ORCID = "0000-0003-4097-6326")),
15 | person("Christopher", "Gandrud", role = "ctb"),
16 | person("Andrew", "MacDonald", role = "ctb"),
17 | person("Ista", "Zahn", role = "ctb"),
18 | person("Stanislaus", "Stadlmann", role = "ctb"),
19 | person("Ruaridh", "Williamson", role = "ctb", email = "ruaridh.williamson@gmail.com"),
20 | person("Patrick", "Kennedy", role = "ctb"),
21 | person("Ryan", "Price", email = "ryapric@gmail.com", role = "ctb"),
22 | person("Trevor L", "Davis", email = "trevor.l.davis@gmail.com", role = "ctb"),
23 | person("Nathan", "Day", email = "nathancday@gmail.com", role = "ctb"),
24 | person("Bill", "Denney",
25 | email="wdenney@humanpredictions.com",
26 | role="ctb",
27 | comment=c(ORCID="0000-0002-5759-428X")),
28 | person("Alex", "Bokov", email = "alex.bokov@gmail.com", role = "ctb",
29 | comment=c(ORCID="0000-0002-0511-9815")),
30 | person("Hugo", "Gruson", role = "ctb", comment = c(ORCID = "0000-0002-4094-1476"))
31 | )
32 | Description: Streamlined data import and export by making assumptions that
33 | the user is probably willing to make: 'import()' and 'export()' determine
34 | the data format from the file extension, reasonable defaults are used for
35 | data import and export, web-based import is natively supported (including
36 | from SSL/HTTPS), compressed files can be read directly, and fast import
37 | packages are used where appropriate. An additional convenience function,
38 | 'convert()', provides a simple method for converting between file types.
39 | URL: https://gesistsa.github.io/rio/, https://github.com/gesistsa/rio
40 | BugReports: https://github.com/gesistsa/rio/issues
41 | Depends:
42 | R (>= 4.0)
43 | Imports:
44 | tools,
45 | stats,
46 | utils,
47 | foreign,
48 | haven (>= 1.1.2),
49 | curl (>= 0.6),
50 | data.table (>= 1.11.2),
51 | readxl (>= 0.1.1),
52 | tibble,
53 | writexl,
54 | lifecycle,
55 | R.utils,
56 | readr
57 | Suggests:
58 | datasets,
59 | bit64,
60 | testthat,
61 | knitr,
62 | magrittr,
63 | clipr,
64 | fst,
65 | hexView,
66 | jsonlite,
67 | pzfx,
68 | readODS (>= 2.1.0),
69 | rmarkdown,
70 | rmatio,
71 | xml2 (>= 1.2.0),
72 | yaml,
73 | qs,
74 | arrow (>= 0.17.0),
75 | stringi,
76 | withr,
77 | nanoparquet
78 | License: GPL-2
79 | VignetteBuilder: knitr
80 | Encoding: UTF-8
81 | RoxygenNote: 7.3.1
82 | Roxygen: list(markdown = TRUE)
83 | Config/Needs/website: gesistsa/tsatemplate
84 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | pkg = $(shell basename $(CURDIR))
2 |
3 | all: build
4 |
5 | NAMESPACE: R/*
6 | Rscript -e "devtools::document()"
7 |
8 | README.md: README.Rmd
9 | Rscript -e "knitr::knit('README.Rmd')"
10 |
11 | R/sysdata.rda: data-raw/single.json
12 | Rscript data-raw/convert.R
13 | Rscript -e "devtools::build_readme()"
14 | README.html: README.md
15 | pandoc -o README.html README.md
16 |
17 | ../$(pkg)*.tar.gz: DESCRIPTION NAMESPACE README.md R/* man/* tests/testthat/* po/R-rio.pot R/sysdata.rda
18 | cd ../ && R CMD build $(pkg)
19 |
20 | build: ../$(pkg)*.tar.gz
21 |
22 | check: ../$(pkg)*.tar.gz
23 | cd ../ && R CMD check $(pkg)*.tar.gz
24 | rm ../$(pkg)*.tar.gz
25 |
26 | install: ../$(pkg)*.tar.gz
27 | cd ../ && R CMD INSTALL $(pkg)*.tar.gz
28 | rm ../$(pkg)*.tar.gz
29 |
30 | website: R/* README.md DESCRIPTION
31 | Rscript -e "pkgdown::build_site()"
32 |
33 | po/R-rio.pot: R/* DESCRIPTION
34 | Rscript -e "tools::update_pkg_po('.')"
35 |
36 | translations: po/R-rio.pot
37 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | S3method(.export,rio_arff)
4 | S3method(.export,rio_clipboard)
5 | S3method(.export,rio_csv)
6 | S3method(.export,rio_csv2)
7 | S3method(.export,rio_csvy)
8 | S3method(.export,rio_dbf)
9 | S3method(.export,rio_dta)
10 | S3method(.export,rio_dump)
11 | S3method(.export,rio_feather)
12 | S3method(.export,rio_fods)
13 | S3method(.export,rio_fst)
14 | S3method(.export,rio_fwf)
15 | S3method(.export,rio_html)
16 | S3method(.export,rio_json)
17 | S3method(.export,rio_matlab)
18 | S3method(.export,rio_ods)
19 | S3method(.export,rio_parquet)
20 | S3method(.export,rio_psv)
21 | S3method(.export,rio_pzfx)
22 | S3method(.export,rio_qs)
23 | S3method(.export,rio_r)
24 | S3method(.export,rio_rda)
25 | S3method(.export,rio_rdata)
26 | S3method(.export,rio_rds)
27 | S3method(.export,rio_sas7bdat)
28 | S3method(.export,rio_sav)
29 | S3method(.export,rio_tsv)
30 | S3method(.export,rio_txt)
31 | S3method(.export,rio_xlsx)
32 | S3method(.export,rio_xml)
33 | S3method(.export,rio_xpt)
34 | S3method(.export,rio_yml)
35 | S3method(.export,rio_zsav)
36 | S3method(.import,rio_arff)
37 | S3method(.import,rio_clipboard)
38 | S3method(.import,rio_csv)
39 | S3method(.import,rio_csv2)
40 | S3method(.import,rio_csvy)
41 | S3method(.import,rio_dat)
42 | S3method(.import,rio_dbf)
43 | S3method(.import,rio_dif)
44 | S3method(.import,rio_dta)
45 | S3method(.import,rio_dump)
46 | S3method(.import,rio_eviews)
47 | S3method(.import,rio_feather)
48 | S3method(.import,rio_fods)
49 | S3method(.import,rio_fortran)
50 | S3method(.import,rio_fst)
51 | S3method(.import,rio_fwf)
52 | S3method(.import,rio_html)
53 | S3method(.import,rio_json)
54 | S3method(.import,rio_matlab)
55 | S3method(.import,rio_mtp)
56 | S3method(.import,rio_ods)
57 | S3method(.import,rio_parquet)
58 | S3method(.import,rio_psv)
59 | S3method(.import,rio_pzfx)
60 | S3method(.import,rio_qs)
61 | S3method(.import,rio_r)
62 | S3method(.import,rio_rda)
63 | S3method(.import,rio_rdata)
64 | S3method(.import,rio_rds)
65 | S3method(.import,rio_rec)
66 | S3method(.import,rio_sas7bdat)
67 | S3method(.import,rio_sav)
68 | S3method(.import,rio_spss)
69 | S3method(.import,rio_syd)
70 | S3method(.import,rio_tsv)
71 | S3method(.import,rio_txt)
72 | S3method(.import,rio_xls)
73 | S3method(.import,rio_xlsx)
74 | S3method(.import,rio_xml)
75 | S3method(.import,rio_xpt)
76 | S3method(.import,rio_yml)
77 | S3method(.import,rio_zsav)
78 | S3method(characterize,data.frame)
79 | S3method(characterize,default)
80 | S3method(factorize,data.frame)
81 | S3method(factorize,default)
82 | export(characterize)
83 | export(convert)
84 | export(export)
85 | export(export_list)
86 | export(factorize)
87 | export(gather_attrs)
88 | export(get_ext)
89 | export(get_info)
90 | export(import)
91 | export(import_list)
92 | export(install_formats)
93 | export(show_unsupported_formats)
94 | export(spread_attrs)
95 |
--------------------------------------------------------------------------------
/R/characterize.R:
--------------------------------------------------------------------------------
1 | #' @rdname characterize
2 | #' @title Character conversion of labelled data
3 | #' @description Convert labelled variables to character or factor
4 | #' @param x A vector or data frame.
5 | #' @param coerce_character A logical indicating whether to additionally coerce character columns to factor (in `factorize`). Default `FALSE`.
6 | #' @param \dots additional arguments passed to methods
7 | #' @details `characterize` converts a vector with a `labels` attribute of named levels into a character vector. `factorize` does the same but to factors. This can be useful at two stages of a data workflow: (1) importing labelled data from metadata-rich file formats (e.g., Stata or SPSS), and (2) exporting such data to plain text files (e.g., CSV) in a way that preserves information.
8 | #' @return a character vector (for `characterize`) or factor vector (for `factorize`)
9 | #' @examples
10 | #' ## vector method
11 | #' x <- structure(1:4, labels = c("A" = 1, "B" = 2, "C" = 3))
12 | #' characterize(x)
13 | #' factorize(x)
14 | #'
15 | #' ## data frame method
16 | #' x <- data.frame(v1 = structure(1:4, labels = c("A" = 1, "B" = 2, "C" = 3)),
17 | #' v2 = structure(c(1,0,0,1), labels = c("foo" = 0, "bar" = 1)))
18 | #' str(factorize(x))
19 | #' str(characterize(x))
20 | #'
21 | #' ## Application
22 | #' csv_file <- tempfile(fileext = ".csv")
23 | #' ## comparison of exported file contents
24 | #' import(export(x, csv_file))
25 | #' import(export(factorize(x), csv_file))
26 | #' @seealso [gather_attrs()]
27 | #' @export
28 | characterize <- function(x, ...) {
29 | UseMethod("characterize")
30 | }
31 |
32 | #' @rdname characterize
33 | #' @export
34 | factorize <- function(x, ...) {
35 | UseMethod("factorize")
36 | }
37 |
38 | #' @rdname characterize
39 | #' @export
40 | characterize.default <- function(x, ...) {
41 | # retain variable label, if present
42 | if (!is.null(attributes(x)[["label"]])) {
43 | varlab <- attributes(x)[["label"]]
44 | } else {
45 | varlab <- NULL
46 | }
47 |
48 | if (!is.null(attributes(x)[["labels"]])) {
49 | x <- as.character(factorize(x, ...))
50 | if (!is.null(varlab)) {
51 | attr(x, "label") <- varlab
52 | }
53 | }
54 |
55 | return(x)
56 | }
57 |
58 | #' @rdname characterize
59 | #' @export
60 | characterize.data.frame <- function(x, ...) {
61 | x[] <- lapply(x, characterize, ...)
62 | x
63 | }
64 |
65 | #' @rdname characterize
66 | #' @export
67 | factorize.default <- function(x, coerce_character=FALSE, ...) {
68 | # retain variable label, if present
69 | if (!is.null(attributes(x)[["label"]])) {
70 | varlab <- attributes(x)[["label"]]
71 | } else {
72 | varlab <- NULL
73 | }
74 |
75 | if (!is.null(attributes(x)[["labels"]])) {
76 | x <- factor(x, attributes(x)[["labels"]], names(attributes(x)[["labels"]]), ...)
77 | } else if (is.character(x) && isTRUE(coerce_character)) {
78 | levs <- sort(unique(x))
79 | x <- factor(x, levs)
80 | }
81 |
82 | if (!is.null(varlab)) {
83 | attr(x, "label") <- varlab
84 | }
85 |
86 | return(x)
87 | }
88 |
89 | #' @rdname characterize
90 | #' @export
91 | factorize.data.frame <- function(x, ...) {
92 | x[] <- lapply(x, factorize, ...)
93 | x
94 | }
95 |
--------------------------------------------------------------------------------
/R/compression.R:
--------------------------------------------------------------------------------
1 | find_compress <- function(f) {
2 | if (endsWith(f, ".zip")) {
3 | return(list(file = sub("\\.zip$", "", f), compress = "zip"))
4 | }
5 | if (endsWith(f, ".tar.gz")) {
6 | return(list(file = sub("\\.tar\\.gz$", "", f), compress = "tar.gz"))
7 | }
8 | if (endsWith(f, ".tgz")) {
9 | return(list(file = sub("\\.tgz$", "", f), compress = "tar.gz"))
10 | }
11 | if (endsWith(f, ".tar.bz2")) {
12 | return(list(file = sub("\\.tar\\.bz2$", "", f), compress = "tar.bz2"))
13 | }
14 | if (endsWith(f, ".tbz2")) {
15 | return(list(file = sub("\\.tbz2$", "", f), compress = "tar.bz2"))
16 | }
17 | if (endsWith(f, ".tar")) {
18 | return(list(file = sub("\\.tar$", "", f), compress = "tar"))
19 | }
20 | if (endsWith(f, ".gzip")) {
21 | ## weird
22 | return(list(file = sub("\\.gzip$", "", f), compress = "gzip"))
23 | }
24 | if (endsWith(f, ".gz")) {
25 | return(list(file = sub("\\.gz$", "", f), compress = "gzip"))
26 | }
27 | if (endsWith(f, ".bz2")) {
28 | return(list(file = sub("\\.bz2$", "", f), compress = "bzip2"))
29 | }
30 | if (endsWith(f, ".bzip2")) {
31 | ## weird
32 | return(list(file = sub("\\.bzip2$", "", f), compress = "bzip2"))
33 | }
34 | return(list(file = f, compress = NA_character_))
35 | }
36 |
37 | compress_out <- function(cfile, filename, type = c("zip", "tar", "tar.gz", "tar.bz2", "gzip", "bzip2")) {
38 | type <- ext <- match.arg(type)
39 | cfile2 <- basename(cfile)
40 | filename <- normalizePath(filename)
41 | if (type %in% c("gzip", "bzip2")) {
42 | return(.compress_rutils(filename, cfile, ext = ext))
43 | }
44 | tmp <- tempfile()
45 | dir.create(tmp)
46 | on.exit(unlink(tmp, recursive = TRUE), add = TRUE)
47 | file.copy(from = filename, to = file.path(tmp, basename(filename)), overwrite = TRUE)
48 | wd <- getwd()
49 | on.exit(setwd(wd), add = TRUE) ## for security, see #438 and #319
50 | setwd(tmp)
51 | if (type == "zip") {
52 | o <- utils::zip(cfile2, files = basename(filename))
53 | }
54 | if (type == "tar") {
55 | o <- utils::tar(cfile2, files = basename(filename), compression = "none")
56 | }
57 | if (type == "tar.gz") {
58 | o <- utils::tar(cfile2, files = basename(filename), compression = "gzip")
59 | }
60 | if (type == "tar.bz2") {
61 | o <- utils::tar(cfile2, files = basename(filename), compression = "bzip2")
62 | }
63 | setwd(wd) ## see #438
64 | if (o != 0) {
65 | stop(sprintf("File compression failed for %s!", cfile))
66 | }
67 | file.copy(from = file.path(tmp, cfile2), to = cfile, overwrite = TRUE)
68 | return(cfile)
69 | }
70 |
71 | parse_archive <- function(file, which, file_type, ...) {
72 | if (file_type %in% c("gzip", "bzip2")) {
73 | ## it doesn't have the same interface as unzip
74 | return(.parse_rutils(filename = file, file_type = file_type))
75 | }
76 | if (file_type == "zip") {
77 | extract_func <- utils::unzip
78 | }
79 | if (file_type %in% c("tar", "tar.gz", "tar.bz2")) {
80 | extract_func <- utils::untar
81 | }
82 | file_list <- .list_archive(file, file_type)
83 | d <- tempfile()
84 | dir.create(d)
85 |
86 | if (is.numeric(which)) {
87 | extract_func(file, files = file_list[which], exdir = d)
88 | return(file.path(d, file_list[which]))
89 | }
90 | if (substring(which, 1, 1) != "^") {
91 | which2 <- paste0("^", which)
92 | }
93 | extract_func(file, files = file_list[grep(which2, file_list)[1]], exdir = d)
94 | return(file.path(d, which))
95 | }
96 |
97 | .list_archive <- function(file, file_type = c("zip", "tar", "tar.gz", "tar.bz2")) {
98 | ## just a simple wrapper to unify the interface of utils::unzip and utils::untar
99 | file_type <- match.arg(file_type)
100 | if (file_type == "zip") {
101 | file_list <- utils::unzip(file, list = TRUE)$Name
102 | }
103 | if (file_type %in% c("tar", "tar.gz", "tar.bz2")) {
104 | file_list <- utils::untar(file, list = TRUE)
105 | }
106 | return(file_list)
107 | }
108 |
109 | .compress_rutils <- function(filename, cfile, ext, remove = TRUE, FUN = gzfile) {
110 | ## Caution: Please note that remove = TRUE by default, it will delete `filename`!
111 | if (ext == "bzip2") {
112 | FUN <- bzfile
113 | }
114 | tmp_cfile <- R.utils::compressFile(filename = filename, destname = tempfile(), ext = ext, FUN = FUN, overwrite = TRUE, remove = remove)
115 | file.copy(from = tmp_cfile, to = cfile, overwrite = TRUE)
116 | unlink(tmp_cfile)
117 | return(cfile)
118 | }
119 |
120 | .parse_rutils <- function(filename, file_type) {
121 | if (file_type == "gzip") {
122 | decompression_fun <- gzfile
123 | }
124 | if (file_type == "bzip2") {
125 | decompression_fun <- bzfile
126 | }
127 | destname <- tempfile()
128 | R.utils::decompressFile(filename = filename, destname = destname, temporary = TRUE, remove = FALSE, overwrite = TRUE, FUN = decompression_fun, ext = file_type)
129 | }
130 |
131 | .check_tar_support <- function(file_type, rversion) {
132 | if (file_type %in% c("tar", "tar.gz", "tar.bz2") && rversion < "4.0.3") {
133 | stop("Exporting to tar formats is not supported for this version of R.", call. = FALSE)
134 | }
135 | NULL
136 | }
137 |
138 | .get_compressed_format <- function(cfile, file, file_type, format) {
139 | if (file_type %in% c("gzip", "bzip2")) {
140 | return(ifelse(isFALSE(missing(format)), tolower(format), get_info(find_compress(cfile)$file)$input))
141 | }
142 | ## zip or tar formats, use the decompressed file path
143 | return(ifelse(isFALSE(missing(format)), tolower(format), get_info(file)$input))
144 | }
145 |
--------------------------------------------------------------------------------
/R/convert.R:
--------------------------------------------------------------------------------
1 | #' @title Convert from one file format to another
2 | #' @description This function constructs a data frame from a data file using [import()] and uses [export()] to write the data to disk in the format indicated by the file extension.
3 | #' @param in_file A character string naming an input file.
4 | #' @param out_file A character string naming an output file.
5 | #' @param in_opts A named list of options to be passed to [import()].
6 | #' @param out_opts A named list of options to be passed to [export()].
7 | #' @return A character string containing the name of the output file (invisibly).
8 | #' @examples
9 | #' ## For demo, a temp. file path is created with the file extension .dta (Stata)
10 | #' dta_file <- tempfile(fileext = ".dta")
11 | #' ## .csv
12 | #' csv_file <- tempfile(fileext = ".csv")
13 | #' ## .xlsx
14 | #' xlsx_file <- tempfile(fileext = ".xlsx")
15 | #'
16 | #'
17 | #' ## Create a Stata data file
18 | #' export(mtcars, dta_file)
19 | #'
20 | #' ## convert Stata to CSV and open converted file
21 | #' convert(dta_file, csv_file)
22 | #' import(csv_file)
23 | #'
24 | #' ## correct an erroneous file format
25 | #' export(mtcars, xlsx_file, format = "tsv") ## DON'T DO THIS
26 | #' ## import(xlsx_file) ## ERROR
27 | #' ## convert the file by specifying `in_opts`
28 | #' convert(xlsx_file, xlsx_file, in_opts = list(format = "tsv"))
29 | #' import(xlsx_file)
30 | #'
31 | #' ## convert from the command line:
32 | #' ## Rscript -e "rio::convert('mtcars.dta', 'mtcars.csv')"
33 | #' @seealso [Luca Braglia](https://lbraglia.github.io/) has created a Shiny app called [rioweb](https://github.com/lbraglia/rioweb) that provides access to the file conversion features of rio through a web browser.
34 | #' @export
35 | convert <- function(in_file, out_file, in_opts=list(), out_opts=list()) {
36 | if (missing(out_file)) {
37 | stop("'outfile' is missing with no default")
38 | }
39 | invisible(do.call("export", c(list(file = out_file, x = do.call("import", c(list(file=in_file), in_opts))), out_opts)))
40 | }
41 |
--------------------------------------------------------------------------------
/R/export.R:
--------------------------------------------------------------------------------
1 | #' @rdname export
2 | #' @title Export
3 | #' @description Write data.frame to a file
4 | #' @param x A data frame, matrix or a single-item list of data frame to be written into a file. Exceptions to this rule are that `x` can be a list of multiple data frames if the output file format is an OpenDocument Spreadsheet (.ods, .fods), Excel .xlsx workbook, .Rdata file, or HTML file, or a variety of R objects if the output file format is RDS or JSON. See examples.) To export a list of data frames to multiple files, use [export_list()] instead.
5 | #' @param file A character string naming a file. Must specify `file` and/or `format`.
6 | #' @param format An optional character string containing the file format, which can be used to override the format inferred from `file` or, in lieu of specifying `file`, a file with the symbol name of `x` and the specified file extension will be created. Must specify `file` and/or `format`. Shortcuts include: \dQuote{,} (for comma-separated values), \dQuote{;} (for semicolon-separated values), \dQuote{|} (for pipe-separated values), and \dQuote{dump} for [base::dump()].
7 | #' @param \dots Additional arguments for the underlying export functions. This can be used to specify non-standard arguments. See examples.
8 | #' @return The name of the output file as a character string (invisibly).
9 | #' @details This function exports a data frame or matrix into a file with file format based on the file extension (or the manually specified format, if `format` is specified).
10 | #'
11 | #' The output file can be to a compressed directory, simply by adding an appropriate additional extensiont to the `file` argument, such as: \dQuote{mtcars.csv.tar}, \dQuote{mtcars.csv.zip}, or \dQuote{mtcars.csv.gz}.
12 | #'
13 | #' `export` supports many file formats. See the documentation for the underlying export functions for optional arguments that can be passed via `...`
14 | #'
15 | #' \itemize{
16 | #' \item Comma-separated data (.csv), using [data.table::fwrite()]
17 | #' \item Pipe-separated data (.psv), using [data.table::fwrite()]
18 | #' \item Tab-separated data (.tsv), using [data.table::fwrite()]
19 | #' \item SAS (.sas7bdat), using [haven::write_sas()].
20 | #' \item SAS XPORT (.xpt), using [haven::write_xpt()].
21 | #' \item SPSS (.sav), using [haven::write_sav()]
22 | #' \item SPSS compressed (.zsav), using [haven::write_sav()]
23 | #' \item Stata (.dta), using [haven::write_dta()]. Note that variable/column names containing dots (.) are not allowed and will produce an error.
24 | #' \item Excel (.xlsx), using [writexl::write_xlsx()]. `x` can also be a list of data frames; the list entry names are used as sheet names.
25 | #' \item R syntax object (.R), using [base::dput()] (by default) or [base::dump()] (if `format = 'dump'`)
26 | #' \item Saved R objects (.RData,.rda), using [base::save()]. In this case, `x` can be a data frame, a named list of objects, an R environment, or a character vector containing the names of objects if a corresponding `envir` argument is specified.
27 | #' \item Serialized R objects (.rds), using [base::saveRDS()]. In this case, `x` can be any serializable R object.
28 | #' \item Serialized R objects (.qs), using [qs::qsave()], which is
29 | #' significantly faster than .rds. This can be any R
30 | #' object (not just a data frame).
31 | #' \item "XBASE" database files (.dbf), using [foreign::write.dbf()]
32 | #' \item Weka Attribute-Relation File Format (.arff), using [foreign::write.arff()]
33 | #' \item Fixed-width format data (.fwf), using [utils::write.table()] with `row.names = FALSE`, `quote = FALSE`, and `col.names = FALSE`
34 | #' \item [CSVY](https://github.com/csvy) (CSV with a YAML metadata header) using [data.table::fwrite()].
35 | #' \item Apache Arrow Parquet (.parquet), using [nanoparquet::write_parquet()]
36 | #' \item Feather R/Python interchange format (.feather), using [arrow::write_feather()]
37 | #' \item Fast storage (.fst), using [fst::write.fst()]
38 | #' \item JSON (.json), using [jsonlite::toJSON()]. In this case, `x` can be a variety of R objects, based on class mapping conventions in this paper: [https://arxiv.org/abs/1403.2805](https://arxiv.org/abs/1403.2805).
39 | #' \item Matlab (.mat), using [rmatio::write.mat()]
40 | #' \item OpenDocument Spreadsheet (.ods, .fods), using [readODS::write_ods()] or [readODS::write_fods()].
41 | #' \item HTML (.html), using a custom method based on [xml2::xml_add_child()] to create a simple HTML table and [xml2::write_xml()] to write to disk.
42 | #' \item XML (.xml), using a custom method based on [xml2::xml_add_child()] to create a simple XML tree and [xml2::write_xml()] to write to disk.
43 | #' \item YAML (.yml), using [yaml::write_yaml()], default to write the content with UTF-8. Might not work on some older systems, e.g. default Windows locale for R <= 4.2.
44 | #' \item Clipboard export (on Windows and Mac OS), using [utils::write.table()] with `row.names = FALSE`
45 | #' }
46 | #'
47 | #' When exporting a data set that contains label attributes (e.g., if imported from an SPSS or Stata file) to a plain text file, [characterize()] can be a useful pre-processing step that records value labels into the resulting file (e.g., `export(characterize(x), "file.csv")`) rather than the numeric values.
48 | #'
49 | #' Use [export_list()] to export a list of dataframes to separate files.
50 | #'
51 | #' @examples
52 | #' ## For demo, a temp. file path is created with the file extension .csv
53 | #' csv_file <- tempfile(fileext = ".csv")
54 | #' ## .xlsx
55 | #' xlsx_file <- tempfile(fileext = ".xlsx")
56 | #'
57 | #' ## create CSV to import
58 | #' export(iris, csv_file)
59 | #'
60 | #' ## You can certainly export your data with the file name, which is not a variable:
61 | #' ## import(mtcars, "car_data.csv")
62 | #'
63 | #' ## pass arguments to the underlying function
64 | #' ## data.table::fwrite is the underlying function and `col.names` is an argument
65 | #' export(iris, csv_file, col.names = FALSE)
66 | #'
67 | #' ## export a list of data frames as worksheets
68 | #' export(list(a = mtcars, b = iris), xlsx_file)
69 | #'
70 | #' # NOT RECOMMENDED
71 | #'
72 | #' ## specify `format` to override default format
73 | #' export(iris, xlsx_file, format = "csv") ## That's confusing
74 | #' ## You can also specify only the format; in the following case
75 | #' ## "mtcars.dta" is written [also confusing]
76 | #'
77 | #' ## export(mtcars, format = "stata")
78 | #' @seealso [characterize()], [import()], [convert()], [export_list()]
79 | #' @export
80 | export <- function(x, file, format, ...) {
81 | .check_file(file, single_only = TRUE)
82 | if (missing(file) && missing(format)) {
83 | stop("Must specify 'file' and/or 'format'")
84 | }
85 | if (!missing(file)) {
86 | cfile <- file
87 | f <- find_compress(file)
88 | file <- f$file
89 | compress <- f$compress
90 | format <- ifelse(isFALSE(missing(format)), tolower(format), get_info(file)$input)
91 | } else {
92 | format <- .standardize_format(format)
93 | file <- paste0(as.character(substitute(x)), ".", format)
94 | compress <- NA_character_
95 | }
96 | .check_tar_support(compress, getRversion())
97 | format <- .standardize_format(format)
98 | outfile <- file
99 | if (is.matrix(x) || inherits(x, "ArrowTabular")) {
100 | x <- as.data.frame(x)
101 | }
102 | if (!is.data.frame(x) && is.list(x) && length(x) == 1 && is.data.frame(x[[1]]) &&
103 | !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) {
104 | x <- x[[1]] ## fix 385
105 | }
106 | if (!is.data.frame(x) && !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) {
107 | stop("'x' is not a data.frame or matrix", call. = FALSE)
108 | }
109 | if (format == "gz") {
110 | format <- get_info(tools::file_path_sans_ext(file, compression = FALSE))$format
111 | if (format != "csv") {
112 | stop("gz is only supported for csv (for now).", call. = FALSE)
113 | }
114 | }
115 | .create_directory_if_not_exists(file = file) ## fix 347
116 | class(file) <- c(paste0("rio_", format), class(file))
117 | .export(file = file, x = x, ...)
118 | if (!is.na(compress)) {
119 | cfile <- compress_out(cfile = cfile, filename = file, type = compress)
120 | unlink(file)
121 | return(invisible(cfile))
122 | }
123 | invisible(unclass(outfile))
124 | }
125 |
--------------------------------------------------------------------------------
/R/export_list.R:
--------------------------------------------------------------------------------
1 | #' @title Export list of data frames to files
2 | #' @description Use [export()] to export a list of data frames to a vector of file names or a filename pattern.
3 | #' @param x A list of data frames to be written to files.
4 | #' @param file A character vector string containing a single file name with a `\%s` wildcard placeholder, or a vector of file paths for multiple files to be imported. If `x` elements are named, these will be used in place of `\%s`, otherwise numbers will be used; all elements must be named for names to be used.
5 | #' @param archive character. Either empty string (default) to save files in current
6 | #' directory, a path to a (new) directory, or a .zip/.tar file to compress all
7 | #' files into an archive.
8 | #' @param \dots Additional arguments passed to [export()].
9 | #' @return The name(s) of the output file(s) as a character vector (invisibly).
10 | #' @details [export()] can export a list of data frames to a single multi-dataset file (e.g., an Rdata or Excel .xlsx file). Use `export_list` to export such a list to *multiple* files.
11 | #' @examples
12 | #' ## For demo, a temp. file path is created with the file extension .xlsx
13 | #' xlsx_file <- tempfile(fileext = ".xlsx")
14 | #' export(
15 | #' list(
16 | #' mtcars1 = mtcars[1:10, ],
17 | #' mtcars2 = mtcars[11:20, ],
18 | #' mtcars3 = mtcars[21:32, ]
19 | #' ),
20 | #' xlsx_file
21 | #' )
22 | #'
23 | #' # import a single file from multi-object workbook
24 | #' import(xlsx_file, sheet = "mtcars1")
25 | #' # import all worksheets, the return value is a list
26 | #' import_list(xlsx_file)
27 |
28 | #' library('datasets')
29 | #' export(list(mtcars1 = mtcars[1:10,],
30 | #' mtcars2 = mtcars[11:20,],
31 | #' mtcars3 = mtcars[21:32,]),
32 | #' xlsx_file <- tempfile(fileext = ".xlsx")
33 | #' )
34 | #'
35 | #' # import all worksheets
36 | #' list_of_dfs <- import_list(xlsx_file)
37 | #'
38 | #' # re-export as separate named files
39 | #'
40 | #' ## export_list(list_of_dfs, file = c("file1.csv", "file2.csv", "file3.csv"))
41 | #'
42 | #' # re-export as separate files using a name pattern; using the names in the list
43 | #' ## This will be written as "mtcars1.csv", "mtcars2.csv", "mtcars3.csv"
44 | #'
45 | #' ## export_list(list_of_dfs, file = "%s.csv")
46 | #' @seealso [import()], [import_list()], [export()]
47 | #' @export
48 | export_list <- function(x, file, archive = "", ...) {
49 | .check_file(file, single_only = FALSE)
50 | archive_format <- find_compress(archive)
51 | supported_archive_formats <- c("zip", "tar", "tar.gz", "tar.bz2")
52 | if (!is.na(archive_format$compress) && !archive_format$compress %in% supported_archive_formats) {
53 | stop("'archive' is specified but format is not supported. Only zip and tar formats are supported.", call. = FALSE)
54 | }
55 | if (inherits(x, "data.frame")) {
56 | stop("'x' must be a list. Perhaps you want export()?", call. = FALSE)
57 | }
58 | .check_tar_support(archive_format$compress, getRversion())
59 |
60 | outfiles <- .create_outfiles(file, x)
61 |
62 | if (is.na(archive_format$compress) && archive_format$file != "") {
63 | outfiles <- file.path(archive_format$file, outfiles)
64 | }
65 | outfiles_normalized <- normalizePath(outfiles, mustWork = FALSE)
66 |
67 | out <- list()
68 | for (f in seq_along(x)) {
69 | out[[f]] <- try(export(x[[f]], file = outfiles_normalized[f], ...), silent = TRUE)
70 | if (inherits(out[[f]], "try-error")) {
71 | warning(sprintf("Export failed for element %d, filename: %s", f, outfiles[f]))
72 | }
73 | }
74 | if (!is.na(archive_format$compress)) {
75 | .create_directory_if_not_exists(archive)
76 | compress_out(archive, outfiles_normalized, type = archive_format$compress)
77 | unlink(outfiles_normalized)
78 | return(invisible(archive))
79 | }
80 | return(invisible(outfiles))
81 | }
82 |
--------------------------------------------------------------------------------
/R/extensions.R:
--------------------------------------------------------------------------------
1 | .import <- function(file, ...) {
2 | UseMethod(".import")
3 | }
4 |
5 | .import.default <- function(file, ...) {
6 | fileinfo <- get_info(file) ## S3 can't be dispatched
7 | if (fileinfo$type == "unknown" || is.na(fileinfo$import_function) || fileinfo$import_function == "") {
8 | stop("Format not supported", call. = FALSE)
9 | }
10 | if (fileinfo$type == "known") {
11 | stop(sprintf(gettext("%s format not supported. Consider using the '%s()' function"),
12 | fileinfo$format, fileinfo$import_function), call. = FALSE)
13 | }
14 | if (fileinfo$type == "enhance") {
15 | pkg <- strsplit(fileinfo$import_function, "::", fixed = TRUE)[[1]][1]
16 | stop(sprintf(gettext("Import support for the %s format is exported by the %s package. Run 'library(%s)' then try again."),
17 | fileinfo$format, pkg, pkg), call. = FALSE)
18 | }
19 | }
20 |
21 | .export <- function(file, x, ...) {
22 | UseMethod(".export")
23 | }
24 |
25 | .export.default <- function(file, x, ...) {
26 | fileinfo <- get_info(file)
27 | if (fileinfo$type == "unknown" || is.na(fileinfo$export_function) || fileinfo$export_function == "") {
28 | stop("Format not supported", call. = FALSE)
29 | }
30 | if (fileinfo$type == "known") {
31 | stop(sprintf(gettext("%s format not supported. Consider using the '%s()' function"),
32 | fileinfo$format, fileinfo$export_function), call. = FALSE)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/R/gather_attrs.R:
--------------------------------------------------------------------------------
1 | #' @rdname gather_attrs
2 | #' @title Gather attributes from data frame variables
3 | #' @description `gather_attrs` moves variable-level attributes to the data frame level and `spread_attrs` reverses that operation.
4 | #' @details [import()] attempts to standardize the return value from the various import functions to the extent possible, thus providing a uniform data structure regardless of what import package or function is used. It achieves this by storing any optional variable-related attributes at the variable level (i.e., an attribute for `mtcars$mpg` is stored in `attributes(mtcars$mpg)` rather than `attributes(mtcars)`). `gather_attrs` moves these to the data frame level (i.e., in `attributes(mtcars)`). `spread_attrs` moves attributes back to the variable level.
5 | #' @param x A data frame.
6 | #' @return `x`, with variable-level attributes stored at the data frame level.
7 | #' @seealso [import()], [characterize()]
8 | #' @export
9 | gather_attrs <- function(x) {
10 | if (!inherits(x, "data.frame")) {
11 | stop("'x' is not a data.frame")
12 | }
13 | dfattrs <- attributes(x)
14 | if ("label" %in% names(dfattrs)) {
15 | names(dfattrs)[names(dfattrs) == "label"] <- "title"
16 | }
17 | varattrs <- rep(list(list()), length(x))
18 | for (i in seq_along(x)) {
19 | a <- attributes(x[[i]])
20 | varattrs[[i]] <- a[!names(a) %in% c("levels", "class")]
21 | attr(x[[i]], "label") <- NULL
22 | if (any(grepl("labelled", class(x[[i]]), fixed = TRUE))) {
23 | x[[i]] <- haven::zap_labels(x[[i]])
24 | }
25 | f <- grep("^format", names(attributes(x[[i]])), value = TRUE)
26 | if (length(f)) {
27 | attr(x[[i]], f) <- NULL
28 | }
29 | rm(f)
30 | }
31 | if (any(lengths(varattrs))) {
32 | attrnames <- sort(unique(unlist(lapply(varattrs, names))))
33 | outattrs <- stats::setNames(lapply(attrnames, function(z) {
34 | stats::setNames(lapply(varattrs, `[[`, z), names(x))
35 | }), attrnames)
36 | attributes(x) <- c(dfattrs, outattrs)
37 | }
38 | x
39 | }
40 |
41 | #' @rdname gather_attrs
42 | #' @export
43 | spread_attrs <- function(x) {
44 | if (!inherits(x, "data.frame")) {
45 | stop("'x' is not a data.frame")
46 | }
47 | dfattrs <- attributes(x)
48 | d_level_attrs <- names(dfattrs) %in% c("row.names", "class", "names", "notes", "title")
49 | varattrs <- dfattrs[!d_level_attrs]
50 | for (i in seq_along(x)) {
51 | a <- attributes(x[[i]])
52 | attributes(x[[i]]) <- c(a, lapply(varattrs, `[[`, i))
53 | }
54 | if ("title" %in% names(dfattrs)) {
55 | names(dfattrs)[names(dfattrs) == "title"] <- "label"
56 | }
57 | attributes(x) <- dfattrs[d_level_attrs]
58 | x
59 | }
60 |
--------------------------------------------------------------------------------
/R/import_list.R:
--------------------------------------------------------------------------------
1 | #' @title Import list of data frames
2 | #' @description Use [import()] to import a list of data frames from a vector of file names or from a multi-object file (Excel workbook, .Rdata file, compressed directory in a zip file or tar archive, or HTML file)
3 | #' @param file A character string containing a single file name for a multi-object file (e.g., Excel workbook, zip file, tar archive, or HTML file), or a vector of file paths for multiple files to be imported.
4 | #' @param which If `file` is a single file path, this specifies which objects should be extracted (passed to [import()]'s `which` argument). Ignored otherwise.
5 | #' @param rbind A logical indicating whether to pass the import list of data frames through [data.table::rbindlist()].
6 | #' @param rbind_label If `rbind = TRUE`, a character string specifying the name of a column to add to the data frame indicating its source file.
7 | #' @param rbind_fill If `rbind = TRUE`, a logical indicating whether to set the `fill = TRUE` (and fill missing columns with `NA`).
8 | #' @param \dots Additional arguments passed to [import()]. Behavior may be unexpected if files are of different formats.
9 | #' @inheritParams import
10 | #' @inheritSection import Trust
11 | #' @inheritSection import Which
12 | #' @inherit import references
13 | #' @return If `rbind=FALSE` (the default), a list of a data frames. Otherwise, that list is passed to [data.table::rbindlist()] with `fill = TRUE` and returns a data frame object of class set by the `setclass` argument; if this operation fails, the list is returned.
14 | #' @details When file is a vector of file paths and any files are missing, those files are ignored (with warnings) and this function will not raise any error. For compressed files, the file name must also contain information about the file format of all compressed files, e.g. `files.csv.zip` for this function to work.
15 | #' @examples
16 | #' ## For demo, a temp. file path is created with the file extension .xlsx
17 | #' xlsx_file <- tempfile(fileext = ".xlsx")
18 | #' export(
19 | #' list(
20 | #' mtcars1 = mtcars[1:10, ],
21 | #' mtcars2 = mtcars[11:20, ],
22 | #' mtcars3 = mtcars[21:32, ]
23 | #' ),
24 | #' xlsx_file
25 | #' )
26 | #'
27 | #' # import a single file from multi-object workbook
28 | #' import(xlsx_file, sheet = "mtcars1")
29 | #' # import all worksheets, the return value is a list
30 | #' import_list(xlsx_file)
31 | #'
32 | #' # import and rbind all worksheets, the return value is a data frame
33 | #' import_list(xlsx_file, rbind = TRUE)
34 | #' @seealso [import()], [export_list()], [export()]
35 | #' @export
36 | import_list <- function(file, setclass = getOption("rio.import.class", "data.frame"), which, rbind = FALSE,
37 | rbind_label = "_file", rbind_fill = TRUE, ...) {
38 | .check_file(file, single_only = FALSE)
39 | ## special cases
40 | if (length(file) == 1) {
41 | x <- .read_file_as_list(file = file, which = which, setclass = setclass, rbind = rbind, rbind_label = rbind_label, ...)
42 | } else {
43 | ## note the plural
44 | x <- .read_multiple_files_as_list(files = file, setclass = setclass, rbind = rbind, rbind_label = rbind_label, ...)
45 | }
46 | ## optionally rbind
47 | if (isTRUE(rbind)) {
48 | if (length(x) == 1) {
49 | x <- x[[1L]]
50 | } else {
51 | x2 <- try(data.table::rbindlist(x, fill = rbind_fill), silent = TRUE)
52 | if (inherits(x2, "try-error")) {
53 | warning("Attempt to rbindlist() the data did not succeed. List returned instead.", call. = FALSE)
54 | return(x)
55 | }
56 | x <- x2
57 | }
58 | x <- set_class(x, class = setclass)
59 | }
60 | return(x)
61 | }
62 |
63 | .strip_exts <- function(file) {
64 | vapply(file, function(x) tools::file_path_sans_ext(basename(x)), character(1))
65 | }
66 |
67 | .read_multiple_files_as_list <- function(files, setclass, rbind, rbind_label, ...) {
68 | names(files) <- .strip_exts(files)
69 | x <- lapply(files, function(thisfile) {
70 | out <- try(import(thisfile, setclass = setclass, ...), silent = TRUE)
71 | if (inherits(out, "try-error")) {
72 | warning(sprintf("Import failed for %s", thisfile), call. = FALSE)
73 | ##out <- NULL
74 | return(NULL)
75 | } else if (isTRUE(rbind)) {
76 | out[[rbind_label]] <- thisfile
77 | }
78 | structure(out, filename = thisfile)
79 | })
80 | names(x) <- names(files)
81 | return(x)
82 | }
83 |
84 | .read_file_as_list <- function(file, which, setclass, rbind, rbind_label, ...) {
85 | if (R.utils::isUrl(file)) {
86 | file <- remote_to_local(file)
87 | }
88 | if (get_info(file)$format == "rdata") {
89 | return(.import.rio_rdata(file = file, .return_everything = TRUE, ...))
90 | }
91 | archive_format <- find_compress(file)
92 | if (!get_info(file)$format %in% c("html", "xlsx", "xls") && !archive_format$compress %in% c("zip", "tar", "tar.gz", "tar.bz2")) {
93 | which <- 1
94 | whichnames <- NULL
95 | }
96 | ## getting list of `whichnames`
97 | if (get_info(file)$format == "html") {
98 | .check_pkg_availability("xml2")
99 | tables <- xml2::xml_find_all(xml2::read_html(unclass(file)), ".//table")
100 | if (missing(which)) {
101 | which <- seq_along(tables)
102 | }
103 | whichnames <- vapply(xml2::xml_attrs(tables[which]),
104 | function(x) if ("class" %in% names(x)) x["class"] else "",
105 | FUN.VALUE = character(1)
106 | )
107 | names(which) <- whichnames
108 | }
109 | if (get_info(file)$format %in% c("xls", "xlsx")) {
110 | ## .check_pkg_availability("readxl")
111 | whichnames <- readxl::excel_sheets(path = file)
112 | if (missing(which)) {
113 | which <- seq_along(whichnames)
114 | names(which) <- whichnames
115 | } else if (is.character(which)) {
116 | whichnames <- which
117 | } else {
118 | whichnames <- whichnames[which]
119 | }
120 | }
121 | if (archive_format$compress %in% c("zip", "tar", "tar.gz", "tar.bz2")) {
122 | whichnames <- .list_archive(file, archive_format$compress)
123 | if (missing(which)) {
124 | which <- seq_along(whichnames)
125 | names(which) <- .strip_exts(whichnames)
126 | } else if (is.character(which)) {
127 | whichnames <- whichnames[whichnames %in% which]
128 | } else {
129 | names(which) <- .strip_exts(whichnames)
130 | }
131 | }
132 | ## reading all `whichnames`
133 | x <- lapply(which, function(thiswhich) {
134 | out <- try(import(file, setclass = setclass, which = thiswhich, ...), silent = TRUE)
135 | if (inherits(out, "try-error")) {
136 | warning(sprintf("Import failed for %s from %s", thiswhich, file))
137 | out <- NULL
138 | } else if (isTRUE(rbind) && length(which) > 1) {
139 | out[[rbind_label]] <- thiswhich
140 | }
141 | out
142 | })
143 | names(x) <- whichnames
144 | return(x)
145 | }
146 |
--------------------------------------------------------------------------------
/R/onLoad.R:
--------------------------------------------------------------------------------
1 | .onAttach <- function(libname, pkgname) {
2 | if (interactive()) {
3 | w <- uninstalled_formats()
4 | if (length(w)) {
5 | msg <- "Some optional R packages were not installed and therefore some file formats are not supported. Check file support with show_unsupported_formats()"
6 | packageStartupMessage(msg)
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/R/remote_to_local.R:
--------------------------------------------------------------------------------
1 | remote_to_local <- function(file, format) {
2 | if (grepl("docs.google.com/spreadsheets", file, fixed = TRUE)) {
3 | if (missing(format) || (!missing(format) && !format %in% c("csv", "tsv", "xlsx", "ods"))) {
4 | format <- "csv"
5 | }
6 | file <- .convert_google_url(file, export_as = format)
7 | }
8 | if (missing(format)) {
9 | ## try to extract format from URL, see below
10 | format <- .get_ext_temp(file)
11 | } else {
12 | format <- .standardize_format(format)
13 | }
14 | # save file locally
15 | temp_file <- tempfile(fileext = paste0(".", format))
16 | u <- curl::curl_fetch_memory(file)
17 | writeBin(object = u$content, con = temp_file)
18 | if (format != "TMP") { ## the happiest path
19 | return(temp_file)
20 | }
21 | ## fomart = "TMP": try to extract format from curl's final URL
22 | format <- .get_ext_temp(u$url)
23 | if (format != "TMP") { ## contain a file extension, also happy
24 | renamed_file <- sub("TMP$", format, temp_file)
25 | file.copy(from = temp_file, to = renamed_file)
26 | unlink(temp_file)
27 | return(renamed_file)
28 | }
29 | ## try to extract format from headers: read #403 about whether this code is doing anything
30 | h1 <- curl::parse_headers(u$headers)
31 | ## check `Content-Disposition` header
32 | if (!any(grepl("^Content-Disposition", h1))) {
33 | stop("Unrecognized file format. Try specifying with the format argument.")
34 | }
35 | h <- h1[grep("filename", h1, fixed = TRUE)]
36 | if (length(h)) {
37 | f <- regmatches(h, regexpr("(?<=\")(.*)(?", value, "", tag, ">")
70 | }
71 |
72 |
73 | escape_xml <- function(x, replacement = c("&", """, "<", ">", "'")) {
74 | stringi::stri_replace_all_fixed(
75 | str = stringi::stri_enc_toutf8(x), pattern = c("&", "\"", "<", ">", "'"),
76 | replacement = replacement, vectorize_all = FALSE
77 | )
78 | }
79 |
80 | .check_pkg_availability <- function(pkg, lib.loc = NULL) {
81 | if (identical(find.package(pkg, quiet = TRUE, lib.loc = lib.loc), character(0))) {
82 | stop("Suggested package `", pkg, "` is not available. Please install it individually or use `install_formats()`", call. = FALSE)
83 | }
84 | return(invisible(NULL))
85 | }
86 |
87 | .write_as_utf8 <- function(text, file, sep = "") {
88 | writeLines(enc2utf8(text), con = file, sep = sep, useBytes = TRUE)
89 | }
90 |
91 | .check_file <- function(file, single_only = TRUE) {
92 | ## check the `file` argument
93 | if (isTRUE(missing(file))) { ## for the case of export(iris, format = "csv")
94 | return(invisible(NULL))
95 | }
96 | if (isFALSE(inherits(file, "character"))) {
97 | stop("Invalid `file` argument: must be character", call. = FALSE)
98 | }
99 | if (isFALSE(length(file) == 1) && single_only) {
100 | stop("Invalid `file` argument: `file` must be single", call. = FALSE)
101 | }
102 | if (any(is.na(file))) {
103 | stop("Invalid `file` argument: `file` must not be NA", call. = FALSE)
104 | }
105 | invisible(NULL)
106 | }
107 |
108 | .create_directory_if_not_exists <- function(file) {
109 | R.utils::mkdirs(dirname(normalizePath(file, mustWork = FALSE)))
110 | invisible(NULL)
111 | }
112 |
113 | .create_outfiles <- function(file, x) {
114 | names_x <- names(x)
115 | if (length(file) == 1L) {
116 | if (!grepl("%s", file, fixed = TRUE)) {
117 | stop("'file' must have a %s placeholder")
118 | }
119 | if (is.null(names_x)) {
120 | return(sprintf(file, seq_along(x)))
121 | }
122 | if (!all(nzchar(names_x))) {
123 | stop("All elements of 'x' must be named or all must be unnamed")
124 | }
125 | if (anyDuplicated(names_x)) {
126 | stop("Names of elements in 'x' are not unique")
127 | }
128 | return(sprintf(file, names_x))
129 | }
130 | if (length(x) != length(file)) {
131 | stop("'file' must be same length as 'x', or a single pattern with a %s placeholder")
132 | }
133 | if (anyDuplicated(file)) {
134 | stop("File names are not unique")
135 | }
136 | return(file)
137 | }
138 |
139 | .check_trust <- function(trust, format) {
140 | if (is.null(trust)) {
141 | warning("Missing `trust` will be set to FALSE by default for ", format, " in 2.0.0.", call. = FALSE)
142 | trust <- TRUE ## Change this for version 2.0.0
143 | }
144 | if (isFALSE(trust)) {
145 | stop(format, " files may execute arbitary code. Only load ", format, " files that you personally generated or can trust the origin.", call. = FALSE)
146 | }
147 | NULL
148 | }
149 |
150 | .reset_which <- function(file_type, which) {
151 | ## see #412
152 | if (file_type %in% c("zip", "tar", "tar.gz", "tar.bz2")) {
153 | return(1)
154 | }
155 | return(which)
156 | }
157 |
--------------------------------------------------------------------------------
/README.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | output: github_document
3 | ---
4 |
5 | # rio: A Swiss-Army Knife for Data I/O
6 |
7 |
8 | [](https://cran.r-project.org/package=rio)
9 | 
10 |
11 |
12 | ## Overview
13 |
14 | The aim of **rio** is to make data file I/O in R as easy as possible by implementing two main functions in Swiss-army knife style:
15 |
16 | - `import()` provides a painless data import experience by automatically choosing the appropriate import/read function based on file extension (or a specified `format` argument)
17 | - `export()` provides the same painless file recognition for data export/write functionality
18 |
19 | ## Installation
20 |
21 | The package is available on [CRAN](https://cran.r-project.org/package=rio) and can be installed directly in R using `install.packages()`.
22 |
23 | ```R
24 | install.packages("rio")
25 | ```
26 |
27 | The latest development version on GitHub can be installed using:
28 |
29 | ```R
30 | if (!require("remotes")){
31 | install.packages("remotes")
32 | }
33 | remotes::install_github("gesistsa/rio")
34 | ```
35 |
36 | Optional: Installation of additional formats (see below: **Supported file formats**)
37 |
38 | ```R
39 | library(rio)
40 | install_formats()
41 | ```
42 |
43 | ## Usage
44 |
45 | Because **rio** is meant to streamline data I/O, the package is extremely easy to use. Here are some examples of reading, writing, and converting data files.
46 |
47 | ### Import
48 |
49 | Importing data is handled with one function, `import()`:
50 |
51 | ```{r import1}
52 | library("rio")
53 | import("starwars.xlsx")
54 | ```
55 |
56 | ```{r import2}
57 | import("starwars.csv")
58 | ```
59 |
60 | ### Export
61 |
62 | Exporting data is handled with one function, `export()`:
63 |
64 | ```{r exports}
65 | export(mtcars, "mtcars.csv") # comma-separated values
66 | export(mtcars, "mtcars.rds") # R serialized
67 | export(mtcars, "mtcars.sav") # SPSS
68 | ```
69 |
70 | A particularly useful feature of rio is the ability to import from and export to compressed archives (e.g., zip), saving users the extra step of compressing a large exported file, e.g.:
71 |
72 | ```{r export_zip}
73 | export(mtcars, "mtcars.tsv.zip")
74 | ```
75 |
76 | `export()` can also write multiple data frames to respective sheets of an Excel workbook or an HTML file:
77 |
78 | ```{r export_a_list}
79 | export(list(mtcars = mtcars, iris = iris), file = "mtcars.xlsx")
80 | ```
81 |
82 | ## Supported file formats
83 |
84 | **rio** supports a wide range of file formats. To keep the package slim, several formats are supported via "Suggests" packages, which are not installed (or loaded) by default. You can check which formats are **not** supported via:
85 |
86 | ```R
87 | show_unsupported_formats()
88 | ```
89 |
90 | You can install the suggested packages individually, depending your own needs. If you want to install all suggested packages:
91 |
92 | ```R
93 | install_formats()
94 | ```
95 |
96 | The full list of supported formats is below:
97 |
98 | ```{r, include = FALSE}
99 | suppressPackageStartupMessages(library(data.table))
100 | ```
101 |
102 | ```{r featuretable, echo = FALSE}
103 | rf <- data.table(rio:::rio_formats)[!input %in% c(",", ";", "|", "\\t") & type %in% c("import", "suggest", "archive"),]
104 | short_rf <- rf[, paste(input, collapse = " / "), by = format_name]
105 | type_rf <- unique(rf[,c("format_name", "type", "import_function", "export_function", "note")])
106 |
107 | feature_table <- short_rf[type_rf, on = .(format_name)]
108 |
109 | colnames(feature_table)[2] <- "signature"
110 |
111 | setorder(feature_table, "type", "format_name")
112 | feature_table$import_function <- stringi::stri_extract_first(feature_table$import_function, regex = "[a-zA-Z0-9\\.]+")
113 | feature_table$import_function[is.na(feature_table$import_function)] <- ""
114 | feature_table$export_function <- stringi::stri_extract_first(feature_table$export_function, regex = "[a-zA-Z0-9\\.]+")
115 | feature_table$export_function[is.na(feature_table$export_function)] <- ""
116 |
117 | feature_table$type <- ifelse(feature_table$type %in% c("suggest"), "Suggest", "Default")
118 | feature_table <- feature_table[,c("format_name", "signature", "import_function", "export_function", "type", "note")]
119 |
120 | colnames(feature_table) <- c("Name", "Extensions / \"format\"", "Import Package", "Export Package", "Type", "Note")
121 |
122 | knitr::kable(feature_table)
123 | ```
124 |
125 | Additionally, any format that is not supported by **rio** but that has a known R implementation will produce an informative error message pointing to a package and import or export function. Unrecognized formats will yield a simple "Unrecognized file format" error.
126 |
127 | ## Other functions
128 |
129 | ### Convert
130 |
131 | The `convert()` function links `import()` and `export()` by constructing a dataframe from the imported file and immediately writing it back to disk. `convert()` invisibly returns the file name of the exported file, so that it can be used to programmatically access the new file.
132 |
133 | ```{r convert}
134 | convert("mtcars.sav", "mtcars.dta")
135 | ```
136 |
137 | It is also possible to use **rio** on the command-line by calling `Rscript` with the `-e` (expression) argument. For example, to convert a file from Stata (.dta) to comma-separated values (.csv), simply do the following:
138 |
139 | ```
140 | Rscript -e "rio::convert('iris.dta', 'iris.csv')"
141 | ```
142 |
143 | ### *_list
144 |
145 | `import_list()` allows users to import a list of data frames from a multi-object file (such as an Excel workbook, .Rdata file, zip directory, or HTML file):
146 |
147 | ```{r import_list}
148 | str(m <- import_list("mtcars.xlsx"))
149 | ```
150 |
151 | `export_list()` makes it easy to export a list of (possibly named) data frames to multiple files:
152 |
153 | ```{r export_list}
154 | export_list(m, "%s.tsv")
155 | c("mtcars.tsv", "iris.tsv") %in% dir()
156 | ```
157 |
158 | ```{r cleanup, echo=FALSE, results="hide"}
159 | unlink("mtcars.csv")
160 | unlink("mtcars.dta")
161 | unlink("mtcars.sav")
162 | unlink("mtcars.rds")
163 | unlink("mtcars.xlsx")
164 | unlink("mtcars.tsv.zip")
165 | unlink("mtcars.tsv")
166 | unlink("iris.tsv")
167 | ```
168 |
169 | ## Other projects
170 |
171 | ### GUIs
172 |
173 | * [**datamods**](https://cran.r-project.org/package=datamods) provides Shiny modules for importing data via `rio`.
174 | * [**rioweb**](https://github.com/lbraglia/rioweb) that provides access to the file conversion features of `rio`.
175 | * [**GREA**](https://github.com/Stan125/GREA/) is an RStudio add-in that provides an interactive interface for reading in data using `rio`.
176 |
177 | ### Similar packages
178 |
179 | * [**reader**](https://cran.r-project.org/package=reader) handles certain text formats and R binary files
180 | * [**io**](https://cran.r-project.org/package=io) offers a set of custom formats
181 | * [**ImportExport**](https://cran.r-project.org/package=ImportExport) focuses on select binary formats (Excel, SPSS, and Access files) and provides a Shiny interface.
182 | * [**SchemaOnRead**](https://cran.r-project.org/package=SchemaOnRead) iterates through a large number of possible import methods until one works successfully
183 |
--------------------------------------------------------------------------------
/_pkgdown.yml:
--------------------------------------------------------------------------------
1 | url: http://gesistsa.github.io/rio/
2 | template:
3 | package: tsatemplate
4 |
5 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | comment: false
2 |
3 | coverage:
4 | status:
5 | patch: off
6 |
--------------------------------------------------------------------------------
/data-raw/convert.R:
--------------------------------------------------------------------------------
1 | writeLines(
2 | jsonlite::prettify(jsonlite::toJSON(jsonlite::read_json(here::here("data-raw/single.json"), TRUE))),
3 | here::here("data-raw/single.json")
4 | )
5 | rio_formats <- rio::import(here::here("data-raw", "single.json"))
6 |
7 | all_functions <- unlist(rio_formats[rio_formats$type == "suggest", c("import_function", "export_function")], use.names = FALSE)
8 | suggestions <- unique(stats::na.omit(stringi::stri_extract_first(all_functions, regex = "[a-zA-Z0-9\\.]+")))
9 | attr(rio_formats, "suggested_packages") <- c(suggestions, "stringi")
10 | usethis::use_data(rio_formats, overwrite = TRUE, internal = TRUE)
11 |
12 | ## #351
13 |
14 | ## old_data <- jsonlite::read_json(here::here("data-raw/single.json"), TRUE)
15 |
16 | ## new_data <- old_data
17 | ## colnames(new_data)[2] <- "format"
18 |
19 | ## writeLines(jsonlite::prettify(jsonlite::toJSON(new_data)), here::here("data-raw/single.json"))
20 | ## rio_formats <- rio::import(here::here("data-raw", "single.json"))
21 | ## usethis::use_data(rio_formats, overwrite = TRUE, internal = TRUE)
22 |
23 | ## #351 remove ext
24 | ## old_data <- jsonlite::read_json(here::here("data-raw/single.json"), TRUE)
25 | ## new_data <- old_data[, -3]
26 | ## writeLines(jsonlite::prettify(jsonlite::toJSON(new_data)), here::here("data-raw/single.json"))
27 | ## rio_formats <- rio::import(here::here("data-raw", "single.json"))
28 | ## usethis::use_data(rio_formats, overwrite = TRUE, internal = TRUE)
29 |
--------------------------------------------------------------------------------
/data-raw/obsolete/arg_reconcile.R:
--------------------------------------------------------------------------------
1 | ## @title Reconcile an argument list to any function signature.
2 | ##
3 | ## @description Adapt an argument list to a function excluding arguments that
4 | ## will not be recognized by it, redundant arguments, and un-named
5 | ## arguments.
6 | ##
7 | ## @param fun A function to which an argument list needs to be adapted. Use
8 | ## the unquoted name of the function. If it's in a different
9 | ## package then the fully qualified unquoted name (e.g.
10 | ## \code{utils::read.table})
11 | ## @param ... An arbitrary list of named arguments (unnamed ones will be
12 | ## ignored). Arguments in \code{.args} are overridden by
13 | ## arguments of the same name (if any) in \code{...}
14 | ## @param .args A list or \code{alist} of named arguments, to be merged
15 | ## with \code{...}. Arguments in \code{.args} are overridden by
16 | ## arguments of the same name (if any) in \code{...}
17 | ## @param .docall If set to \code{TRUE} will not only clean up the arguments
18 | ## but also execute \code{fun} with those arguments
19 | ## (\code{FALSE} by default) and return the results
20 | ## @param .include Whitelist. If not empty, only arguments named here will be
21 | ## permitted, and only if they satisfy the conditions implied by
22 | ## the other arguments. Evaluated before \code{.remap}.
23 | ## @param .exclude Blacklist. If not empty, arguments named here will be removed
24 | ## even if they satisfy the conditions implied by the other
25 | ## arguments. Evaluated before \code{.remap}.
26 | ## @param .remap An optional named character vector or named list of character
27 | ## values for standardizing arguments that play the same role
28 | ## but have different names in different functions. Evaluated
29 | ## after \code{.exclude} and \code{.include}.
30 | ## @param .warn Whether to issue a warning message (default) when invalid
31 | ## arguments need to be discarded.
32 | ## @param .error If specified, should be the object to return in the event of
33 | ## error. This object will have the error as its
34 | ## \code{error} attribute. If not specified an ordinary error is
35 | ## thrown with an added hint on the documentation to read for
36 | ## troubleshooting. Ignored if \code{.docall} is \code{FALSE}.
37 | ## The point of doing this is fault-tolerance-- if this function
38 | ## is part of a lengthy process where you want to document an
39 | ## error but keep going, you can set \code{.error} to some
40 | ## object of a compatible type. That object will be returned in
41 | ## the event of error and will have as its \code{"error"}
42 | ## attribute the error object.
43 | ## @param .finish A function to run on the result before returning it. Ignored
44 | ## if \code{.docall} is \code{FALSE}.
45 | ##
46 | ## @return Either a named list or the result of calling \code{fun} with the
47 | ## supplied arguments
48 | ##
49 | arg_reconcile <- function(fun, ..., .args = alist(), .docall = FALSE,
50 | .include = c(), .exclude= c(), .remap = list(),
51 | .warn = TRUE, .error = "default", .finish = identity) {
52 | ## capture the formal arguments of the target function
53 | frmls <- formals(fun)
54 | ## both freeform and an explicit list
55 | args <- match.call(expand.dots = FALSE)[["..."]]
56 | if (isTRUE(.docall)) {
57 | for (ii in names(args)) {
58 | try(args[[ii]] <- eval(args[[ii]], parent.frame()))
59 | }
60 | }
61 | ## get rid of duplicate arguments, with freeform arguments
62 | dupes <- names(args)[duplicated(names(args))]
63 | for (ii in dupes) {
64 | args[which(names(args) == ii)[-1]] <- NULL
65 | }
66 | ## Merge ... with .args
67 | args <- c(args, .args)
68 | ## Apply whitelist and blacklist. This step also removes duplicates _between_
69 | ## the freeform (...) and pre-specified (.args) arguments, with ... versions
70 | ## taking precedence over the .args versions. This is a consequence of the
71 | ## intersect() and setdiff() operations and works even if there is no blacklist
72 | ## nor whitelist
73 | if (!missing(.include)) {
74 | args <- args[intersect(names(args), .include)]
75 | }
76 | args <- args[setdiff(names(args), .exclude)]
77 | ## if any remappings of one argument to another are specified, perform them
78 | for (ii in names(.remap)) {
79 | if (!.remap[[ii]] %in% names(args) && ii %in% names(args)) {
80 | args[[.remap[[ii]] ]] <- args[[ii]]
81 | }
82 | }
83 | ## remove any unnamed arguments
84 | args[names(args) == ""] <- NULL
85 | ## if the target function doesn't have "..." as an argument, check to make sure
86 | ## only recognized arguments get passed, optionally with a warning
87 | if (!"..." %in% names(frmls)) {
88 | unused <- setdiff(names(args), names(frmls))
89 | if (length(unused)>0) {
90 | if (isTRUE(.warn)) {
91 | warning("The following arguments were ignored for ",
92 | deparse(substitute(fun)), ":\n", paste(unused, collapse = ", "))
93 | }
94 | args <- args[intersect(names(args), names(frmls))]
95 | }
96 | }
97 | ## the final, cleaned-up arguments either get returned as a list or used on the
98 | ## function, depending on how .docall is set
99 | if (!isTRUE(.docall)) {
100 | return(args)
101 | } else {
102 | ## run the function and return the result case
103 | oo <- try(do.call(fun, args), silent = TRUE)
104 | if (!inherits(oo, "try-error")) {
105 | return(.finish(oo))
106 | } else {
107 | ## construct an informative error... eventually there will be more
108 | ## detailed info here
109 | errorhint <- paste("\nThis error was generated by: ",
110 | deparse(match.call()$fun),
111 | "\nWith the following arguments:\n",
112 | gsub("^list\\(|\\)$", "",
113 | paste(deparse(args, control=c("delayPromises")),
114 | collapse = "\n")))
115 | if (missing(.error)) {
116 | stop(attr(oo, "condition")$message, errorhint)
117 | } else {
118 | attr(.error, "error") <- oo
119 | return(.error)
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/data-raw/obsolete/is_file_text.R:
--------------------------------------------------------------------------------
1 | ## @title Determine whether a file is \dQuote{plain-text} or some sort of binary format
2 | ##
3 | ## @param file Path to the file
4 | ## @param maxsize Maximum number of bytes to read
5 | ## @param text_bytes Which characters are used by normal text (though not
6 | ## necessarily just ASCII). To detect just ASCII, the
7 | ## following value can be used:
8 | ## \code{as.raw(c(7:16, 18, 19, 32:127))}
9 | ##
10 | ## @return A logical
11 | ## @export
12 | ## @examples
13 | ## library(datasets)
14 | ## export(iris, yml_file <- tempfile(fileext = ".yml"))
15 | ## is_file_text(yml_file) # TRUE
16 | ##
17 | ## export(iris, sav_file <- tempfile(fileext = ".sav"))
18 | ## is_file_text(sav_file) # FALSE
19 | ##
20 | ## # cleanup
21 | ## unlink(yml_file)
22 | ## unlink(sav_file)
23 | ##
24 | is_file_text <- function(
25 | file,
26 | maxsize = Inf,
27 | text_bytes = as.raw(c(0x7:0x10, 0x12, 0x13, 0x20:0xFF))
28 | ) {
29 |
30 | ff <- file(file, "rb")
31 | bytes <- readBin(
32 | ff,
33 | raw(),
34 | n = min(file.info(file)$size, maxsize)
35 | )
36 | close(ff)
37 |
38 | return(length(setdiff(bytes, text_bytes)) == 0)
39 | }
40 |
--------------------------------------------------------------------------------
/data-raw/obsolete/old_logo/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gesistsa/rio/f1094bf636f95f5dfcb05408d2ca0960fa792c8e/data-raw/obsolete/old_logo/logo.png
--------------------------------------------------------------------------------
/data-raw/obsolete/old_logo/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
148 |
--------------------------------------------------------------------------------
/data-raw/obsolete/test_is_file_text.R:
--------------------------------------------------------------------------------
1 | context("correctly identifying files as text vs binary")
2 | require("datasets")
3 |
4 | txtformats <- c("arff", "csv", "csv2", "dump", "fwf", "psv", "r", "tsv", "txt")
5 | binformats <- c("dbf", "dta", "rda", "rdata", "rds", "sas7bdat", "sav", "xlsx",
6 | "xpt")
7 | names(iris) <- gsub("\\.", "_", names(iris))
8 |
9 | test_that("Required text formats recognized as text", {
10 | for (xx in txtformats) {
11 | expect_true(is_file_text(export(iris, paste0("iris.", xx))),
12 | label = paste0(xx, " should be text"))
13 | }
14 | })
15 |
16 | test_that("Required non-text formats recognized as non-text", {
17 | for (xx in binformats) {
18 | expect_false(is_file_text(export(iris, paste0("iris.", xx))),
19 | label = paste0(xx, " should not be text"))
20 | }
21 | })
22 |
23 | test_that("csvy recognized as text", {
24 | skip_if_not_installed(pkg = "data.table")
25 | expect_true(is_file_text(export(iris, "iris.csvy")))
26 | })
27 |
28 | test_that("xml and html recognized as text", {
29 | skip_if_not_installed(pkg = "xml2")
30 | expect_true(is_file_text(export(iris, "iris.xml")))
31 | expect_true(is_file_text(export(iris, "iris.html")))
32 | })
33 |
34 | test_that("json recognized as text", {
35 | skip_if_not_installed(pkg = "jsonlite")
36 | expect_true(is_file_text(export(iris, "iris.json")))
37 | })
38 |
39 | test_that("yml recognized as text", {
40 | skip_if_not_installed(pkg = "yaml")
41 | expect_true(is_file_text(export(iris, "iris.yml")))
42 | })
43 |
44 | test_that("pzfx recognized as text", {
45 | skip_if_not_installed(pkg = "pzfx")
46 | expect_true(is_file_text(export(iris[,-5], "iris.pzfx")))
47 | })
48 |
49 | test_that("matlab recognized as binary", {
50 | skip("failing mysteriously")
51 | # skip_if_not_installed(pkg = "rmatio")
52 | expect_false(is_file_text(export(iris, "iris.matlab")))
53 | })
54 |
55 | test_that("ods recognized as binary", {
56 | skip_if_not_installed(pkg = "readODS")
57 | expect_false(is_file_text(export(iris, "iris.ods")))
58 | })
59 |
60 | test_that("fst recognized as binary", {
61 | skip_if_not_installed(pkg = "fst")
62 | expect_false(is_file_text(export(iris, "iris.fst")))
63 | })
64 |
65 | test_that("feather recognized as binary", {
66 | skip_if_not_installed(pkg = "feather")
67 | expect_false(is_file_text(export(iris, "iris.feather")))
68 | })
69 |
70 | unlink(paste0("iris.", c(txtformats, binformats, "csvy", "xml", "html", "json",
71 | "yml", "pzfx", "matlab", "ods", "fst", "feather")))
72 | rm(iris, txtformats, binformats)
73 |
74 |
--------------------------------------------------------------------------------
/data-raw/readme.md:
--------------------------------------------------------------------------------
1 |
2 | Please edit the json file if you have made change related to formats.
3 |
4 | `convert.R` will prettify the json file as well as regenerate the internal data (`R/sysdata.rda`)
5 |
6 | If you prefer, you can also use the `Makefile`
7 |
8 | ```R
9 | make R/sysdata.rda
10 | ```
11 |
12 |
--------------------------------------------------------------------------------
/inst/CITATION:
--------------------------------------------------------------------------------
1 | citHeader("To cite package 'rio' in publications use:")
2 |
3 | bibentry(bibtype = "Manual",
4 | title = "rio: A Swiss-army knife for data file I/O",
5 | author = c(person("Chung-hong", "Chan"), person("Thomas J.", "Leeper"), person("Jason", "Becker"), person("David", "Schoch")),
6 | url = "https://cran.r-project.org/package=rio",
7 | year = 2023)
8 |
--------------------------------------------------------------------------------
/man/characterize.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/characterize.R
3 | \name{characterize}
4 | \alias{characterize}
5 | \alias{factorize}
6 | \alias{characterize.default}
7 | \alias{characterize.data.frame}
8 | \alias{factorize.default}
9 | \alias{factorize.data.frame}
10 | \title{Character conversion of labelled data}
11 | \usage{
12 | characterize(x, ...)
13 |
14 | factorize(x, ...)
15 |
16 | \method{characterize}{default}(x, ...)
17 |
18 | \method{characterize}{data.frame}(x, ...)
19 |
20 | \method{factorize}{default}(x, coerce_character = FALSE, ...)
21 |
22 | \method{factorize}{data.frame}(x, ...)
23 | }
24 | \arguments{
25 | \item{x}{A vector or data frame.}
26 |
27 | \item{\dots}{additional arguments passed to methods}
28 |
29 | \item{coerce_character}{A logical indicating whether to additionally coerce character columns to factor (in \code{factorize}). Default \code{FALSE}.}
30 | }
31 | \value{
32 | a character vector (for \code{characterize}) or factor vector (for \code{factorize})
33 | }
34 | \description{
35 | Convert labelled variables to character or factor
36 | }
37 | \details{
38 | \code{characterize} converts a vector with a \code{labels} attribute of named levels into a character vector. \code{factorize} does the same but to factors. This can be useful at two stages of a data workflow: (1) importing labelled data from metadata-rich file formats (e.g., Stata or SPSS), and (2) exporting such data to plain text files (e.g., CSV) in a way that preserves information.
39 | }
40 | \examples{
41 | ## vector method
42 | x <- structure(1:4, labels = c("A" = 1, "B" = 2, "C" = 3))
43 | characterize(x)
44 | factorize(x)
45 |
46 | ## data frame method
47 | x <- data.frame(v1 = structure(1:4, labels = c("A" = 1, "B" = 2, "C" = 3)),
48 | v2 = structure(c(1,0,0,1), labels = c("foo" = 0, "bar" = 1)))
49 | str(factorize(x))
50 | str(characterize(x))
51 |
52 | ## Application
53 | csv_file <- tempfile(fileext = ".csv")
54 | ## comparison of exported file contents
55 | import(export(x, csv_file))
56 | import(export(factorize(x), csv_file))
57 | }
58 | \seealso{
59 | \code{\link[=gather_attrs]{gather_attrs()}}
60 | }
61 |
--------------------------------------------------------------------------------
/man/convert.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/convert.R
3 | \name{convert}
4 | \alias{convert}
5 | \title{Convert from one file format to another}
6 | \usage{
7 | convert(in_file, out_file, in_opts = list(), out_opts = list())
8 | }
9 | \arguments{
10 | \item{in_file}{A character string naming an input file.}
11 |
12 | \item{out_file}{A character string naming an output file.}
13 |
14 | \item{in_opts}{A named list of options to be passed to \code{\link[=import]{import()}}.}
15 |
16 | \item{out_opts}{A named list of options to be passed to \code{\link[=export]{export()}}.}
17 | }
18 | \value{
19 | A character string containing the name of the output file (invisibly).
20 | }
21 | \description{
22 | This function constructs a data frame from a data file using \code{\link[=import]{import()}} and uses \code{\link[=export]{export()}} to write the data to disk in the format indicated by the file extension.
23 | }
24 | \examples{
25 | ## For demo, a temp. file path is created with the file extension .dta (Stata)
26 | dta_file <- tempfile(fileext = ".dta")
27 | ## .csv
28 | csv_file <- tempfile(fileext = ".csv")
29 | ## .xlsx
30 | xlsx_file <- tempfile(fileext = ".xlsx")
31 |
32 |
33 | ## Create a Stata data file
34 | export(mtcars, dta_file)
35 |
36 | ## convert Stata to CSV and open converted file
37 | convert(dta_file, csv_file)
38 | import(csv_file)
39 |
40 | ## correct an erroneous file format
41 | export(mtcars, xlsx_file, format = "tsv") ## DON'T DO THIS
42 | ## import(xlsx_file) ## ERROR
43 | ## convert the file by specifying `in_opts`
44 | convert(xlsx_file, xlsx_file, in_opts = list(format = "tsv"))
45 | import(xlsx_file)
46 |
47 | ## convert from the command line:
48 | ## Rscript -e "rio::convert('mtcars.dta', 'mtcars.csv')"
49 | }
50 | \seealso{
51 | \href{https://lbraglia.github.io/}{Luca Braglia} has created a Shiny app called \href{https://github.com/lbraglia/rioweb}{rioweb} that provides access to the file conversion features of rio through a web browser.
52 | }
53 |
--------------------------------------------------------------------------------
/man/export.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/export.R
3 | \name{export}
4 | \alias{export}
5 | \title{Export}
6 | \usage{
7 | export(x, file, format, ...)
8 | }
9 | \arguments{
10 | \item{x}{A data frame, matrix or a single-item list of data frame to be written into a file. Exceptions to this rule are that \code{x} can be a list of multiple data frames if the output file format is an OpenDocument Spreadsheet (.ods, .fods), Excel .xlsx workbook, .Rdata file, or HTML file, or a variety of R objects if the output file format is RDS or JSON. See examples.) To export a list of data frames to multiple files, use \code{\link[=export_list]{export_list()}} instead.}
11 |
12 | \item{file}{A character string naming a file. Must specify \code{file} and/or \code{format}.}
13 |
14 | \item{format}{An optional character string containing the file format, which can be used to override the format inferred from \code{file} or, in lieu of specifying \code{file}, a file with the symbol name of \code{x} and the specified file extension will be created. Must specify \code{file} and/or \code{format}. Shortcuts include: \dQuote{,} (for comma-separated values), \dQuote{;} (for semicolon-separated values), \dQuote{|} (for pipe-separated values), and \dQuote{dump} for \code{\link[base:dump]{base::dump()}}.}
15 |
16 | \item{\dots}{Additional arguments for the underlying export functions. This can be used to specify non-standard arguments. See examples.}
17 | }
18 | \value{
19 | The name of the output file as a character string (invisibly).
20 | }
21 | \description{
22 | Write data.frame to a file
23 | }
24 | \details{
25 | This function exports a data frame or matrix into a file with file format based on the file extension (or the manually specified format, if \code{format} is specified).
26 |
27 | The output file can be to a compressed directory, simply by adding an appropriate additional extensiont to the \code{file} argument, such as: \dQuote{mtcars.csv.tar}, \dQuote{mtcars.csv.zip}, or \dQuote{mtcars.csv.gz}.
28 |
29 | \code{export} supports many file formats. See the documentation for the underlying export functions for optional arguments that can be passed via \code{...}
30 |
31 | \itemize{
32 | \item Comma-separated data (.csv), using \code{\link[data.table:fwrite]{data.table::fwrite()}}
33 | \item Pipe-separated data (.psv), using \code{\link[data.table:fwrite]{data.table::fwrite()}}
34 | \item Tab-separated data (.tsv), using \code{\link[data.table:fwrite]{data.table::fwrite()}}
35 | \item SAS (.sas7bdat), using \code{\link[haven:write_sas]{haven::write_sas()}}.
36 | \item SAS XPORT (.xpt), using \code{\link[haven:read_xpt]{haven::write_xpt()}}.
37 | \item SPSS (.sav), using \code{\link[haven:read_spss]{haven::write_sav()}}
38 | \item SPSS compressed (.zsav), using \code{\link[haven:read_spss]{haven::write_sav()}}
39 | \item Stata (.dta), using \code{\link[haven:read_dta]{haven::write_dta()}}. Note that variable/column names containing dots (.) are not allowed and will produce an error.
40 | \item Excel (.xlsx), using \code{\link[writexl:write_xlsx]{writexl::write_xlsx()}}. \code{x} can also be a list of data frames; the list entry names are used as sheet names.
41 | \item R syntax object (.R), using \code{\link[base:dput]{base::dput()}} (by default) or \code{\link[base:dump]{base::dump()}} (if \code{format = 'dump'})
42 | \item Saved R objects (.RData,.rda), using \code{\link[base:save]{base::save()}}. In this case, \code{x} can be a data frame, a named list of objects, an R environment, or a character vector containing the names of objects if a corresponding \code{envir} argument is specified.
43 | \item Serialized R objects (.rds), using \code{\link[base:readRDS]{base::saveRDS()}}. In this case, \code{x} can be any serializable R object.
44 | \item Serialized R objects (.qs), using \code{\link[qs:qsave]{qs::qsave()}}, which is
45 | significantly faster than .rds. This can be any R
46 | object (not just a data frame).
47 | \item "XBASE" database files (.dbf), using \code{\link[foreign:write.dbf]{foreign::write.dbf()}}
48 | \item Weka Attribute-Relation File Format (.arff), using \code{\link[foreign:write.arff]{foreign::write.arff()}}
49 | \item Fixed-width format data (.fwf), using \code{\link[utils:write.table]{utils::write.table()}} with \code{row.names = FALSE}, \code{quote = FALSE}, and \code{col.names = FALSE}
50 | \item \href{https://github.com/csvy}{CSVY} (CSV with a YAML metadata header) using \code{\link[data.table:fwrite]{data.table::fwrite()}}.
51 | \item Apache Arrow Parquet (.parquet), using \code{\link[nanoparquet:write_parquet]{nanoparquet::write_parquet()}}
52 | \item Feather R/Python interchange format (.feather), using \code{\link[arrow:write_feather]{arrow::write_feather()}}
53 | \item Fast storage (.fst), using \code{\link[fst:write_fst]{fst::write.fst()}}
54 | \item JSON (.json), using \code{\link[jsonlite:fromJSON]{jsonlite::toJSON()}}. In this case, \code{x} can be a variety of R objects, based on class mapping conventions in this paper: \url{https://arxiv.org/abs/1403.2805}.
55 | \item Matlab (.mat), using \code{\link[rmatio:write.mat-methods]{rmatio::write.mat()}}
56 | \item OpenDocument Spreadsheet (.ods, .fods), using \code{\link[readODS:write_ods]{readODS::write_ods()}} or \code{\link[readODS:write_ods]{readODS::write_fods()}}.
57 | \item HTML (.html), using a custom method based on \code{\link[xml2:xml_replace]{xml2::xml_add_child()}} to create a simple HTML table and \code{\link[xml2:write_xml]{xml2::write_xml()}} to write to disk.
58 | \item XML (.xml), using a custom method based on \code{\link[xml2:xml_replace]{xml2::xml_add_child()}} to create a simple XML tree and \code{\link[xml2:write_xml]{xml2::write_xml()}} to write to disk.
59 | \item YAML (.yml), using \code{\link[yaml:write_yaml]{yaml::write_yaml()}}, default to write the content with UTF-8. Might not work on some older systems, e.g. default Windows locale for R <= 4.2.
60 | \item Clipboard export (on Windows and Mac OS), using \code{\link[utils:write.table]{utils::write.table()}} with \code{row.names = FALSE}
61 | }
62 |
63 | When exporting a data set that contains label attributes (e.g., if imported from an SPSS or Stata file) to a plain text file, \code{\link[=characterize]{characterize()}} can be a useful pre-processing step that records value labels into the resulting file (e.g., \code{export(characterize(x), "file.csv")}) rather than the numeric values.
64 |
65 | Use \code{\link[=export_list]{export_list()}} to export a list of dataframes to separate files.
66 | }
67 | \examples{
68 | ## For demo, a temp. file path is created with the file extension .csv
69 | csv_file <- tempfile(fileext = ".csv")
70 | ## .xlsx
71 | xlsx_file <- tempfile(fileext = ".xlsx")
72 |
73 | ## create CSV to import
74 | export(iris, csv_file)
75 |
76 | ## You can certainly export your data with the file name, which is not a variable:
77 | ## import(mtcars, "car_data.csv")
78 |
79 | ## pass arguments to the underlying function
80 | ## data.table::fwrite is the underlying function and `col.names` is an argument
81 | export(iris, csv_file, col.names = FALSE)
82 |
83 | ## export a list of data frames as worksheets
84 | export(list(a = mtcars, b = iris), xlsx_file)
85 |
86 | # NOT RECOMMENDED
87 |
88 | ## specify `format` to override default format
89 | export(iris, xlsx_file, format = "csv") ## That's confusing
90 | ## You can also specify only the format; in the following case
91 | ## "mtcars.dta" is written [also confusing]
92 |
93 | ## export(mtcars, format = "stata")
94 | }
95 | \seealso{
96 | \code{\link[=characterize]{characterize()}}, \code{\link[=import]{import()}}, \code{\link[=convert]{convert()}}, \code{\link[=export_list]{export_list()}}
97 | }
98 |
--------------------------------------------------------------------------------
/man/export_list.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/export_list.R
3 | \name{export_list}
4 | \alias{export_list}
5 | \title{Export list of data frames to files}
6 | \usage{
7 | export_list(x, file, archive = "", ...)
8 | }
9 | \arguments{
10 | \item{x}{A list of data frames to be written to files.}
11 |
12 | \item{file}{A character vector string containing a single file name with a \verb{\\\%s} wildcard placeholder, or a vector of file paths for multiple files to be imported. If \code{x} elements are named, these will be used in place of \verb{\\\%s}, otherwise numbers will be used; all elements must be named for names to be used.}
13 |
14 | \item{archive}{character. Either empty string (default) to save files in current
15 | directory, a path to a (new) directory, or a .zip/.tar file to compress all
16 | files into an archive.}
17 |
18 | \item{\dots}{Additional arguments passed to \code{\link[=export]{export()}}.}
19 | }
20 | \value{
21 | The name(s) of the output file(s) as a character vector (invisibly).
22 | }
23 | \description{
24 | Use \code{\link[=export]{export()}} to export a list of data frames to a vector of file names or a filename pattern.
25 | }
26 | \details{
27 | \code{\link[=export]{export()}} can export a list of data frames to a single multi-dataset file (e.g., an Rdata or Excel .xlsx file). Use \code{export_list} to export such a list to \emph{multiple} files.
28 | }
29 | \examples{
30 | ## For demo, a temp. file path is created with the file extension .xlsx
31 | xlsx_file <- tempfile(fileext = ".xlsx")
32 | export(
33 | list(
34 | mtcars1 = mtcars[1:10, ],
35 | mtcars2 = mtcars[11:20, ],
36 | mtcars3 = mtcars[21:32, ]
37 | ),
38 | xlsx_file
39 | )
40 |
41 | # import a single file from multi-object workbook
42 | import(xlsx_file, sheet = "mtcars1")
43 | # import all worksheets, the return value is a list
44 | import_list(xlsx_file)
45 | library('datasets')
46 | export(list(mtcars1 = mtcars[1:10,],
47 | mtcars2 = mtcars[11:20,],
48 | mtcars3 = mtcars[21:32,]),
49 | xlsx_file <- tempfile(fileext = ".xlsx")
50 | )
51 |
52 | # import all worksheets
53 | list_of_dfs <- import_list(xlsx_file)
54 |
55 | # re-export as separate named files
56 |
57 | ## export_list(list_of_dfs, file = c("file1.csv", "file2.csv", "file3.csv"))
58 |
59 | # re-export as separate files using a name pattern; using the names in the list
60 | ## This will be written as "mtcars1.csv", "mtcars2.csv", "mtcars3.csv"
61 |
62 | ## export_list(list_of_dfs, file = "\%s.csv")
63 | }
64 | \seealso{
65 | \code{\link[=import]{import()}}, \code{\link[=import_list]{import_list()}}, \code{\link[=export]{export()}}
66 | }
67 |
--------------------------------------------------------------------------------
/man/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gesistsa/rio/f1094bf636f95f5dfcb05408d2ca0960fa792c8e/man/figures/logo.png
--------------------------------------------------------------------------------
/man/gather_attrs.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/gather_attrs.R
3 | \name{gather_attrs}
4 | \alias{gather_attrs}
5 | \alias{spread_attrs}
6 | \title{Gather attributes from data frame variables}
7 | \usage{
8 | gather_attrs(x)
9 |
10 | spread_attrs(x)
11 | }
12 | \arguments{
13 | \item{x}{A data frame.}
14 | }
15 | \value{
16 | \code{x}, with variable-level attributes stored at the data frame level.
17 | }
18 | \description{
19 | \code{gather_attrs} moves variable-level attributes to the data frame level and \code{spread_attrs} reverses that operation.
20 | }
21 | \details{
22 | \code{\link[=import]{import()}} attempts to standardize the return value from the various import functions to the extent possible, thus providing a uniform data structure regardless of what import package or function is used. It achieves this by storing any optional variable-related attributes at the variable level (i.e., an attribute for \code{mtcars$mpg} is stored in \code{attributes(mtcars$mpg)} rather than \code{attributes(mtcars)}). \code{gather_attrs} moves these to the data frame level (i.e., in \code{attributes(mtcars)}). \code{spread_attrs} moves attributes back to the variable level.
23 | }
24 | \seealso{
25 | \code{\link[=import]{import()}}, \code{\link[=characterize]{characterize()}}
26 | }
27 |
--------------------------------------------------------------------------------
/man/get_info.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/utils.R
3 | \name{get_info}
4 | \alias{get_info}
5 | \alias{get_ext}
6 | \title{Get File Info}
7 | \usage{
8 | get_info(file)
9 |
10 | get_ext(file)
11 | }
12 | \arguments{
13 | \item{file}{A character string containing a filename, file path, or URL.}
14 | }
15 | \value{
16 | For \code{\link[=get_info]{get_info()}}, a list is return with the following slots
17 | \itemize{
18 | \item \code{input} file extension or information used to identify the possible file format
19 | \item \code{format} file format, see \code{format} argument of \code{\link[=import]{import()}}
20 | \item \code{type} "import" (supported by default); "suggest" (supported by suggested packages, see \code{\link[=install_formats]{install_formats()}}); "enhance" and "known " are not directly supported; \code{NA} is unsupported
21 | \item \code{format_name} name of the format
22 | \item \code{import_function} What function is used to import this file
23 | \item \code{export_function} What function is used to export this file
24 | \item \code{file} \code{file}
25 | }
26 | For \code{\link[=get_ext]{get_ext()}}, just \code{input} (usually file extension) is returned; retained for backward compatibility.
27 | }
28 | \description{
29 | A utility function to retrieve the file information of a filename, path, or URL.
30 | }
31 | \examples{
32 | get_info("starwars.xlsx")
33 | get_info("starwars.ods")
34 | get_info("https://github.com/ropensci/readODS/raw/v2.1/starwars.ods")
35 | get_info("~/duran_duran_rio.mp3")
36 | get_ext("clipboard") ## "clipboard"
37 | get_ext("https://github.com/ropensci/readODS/raw/v2.1/starwars.ods")
38 | }
39 |
--------------------------------------------------------------------------------
/man/import_list.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/import_list.R
3 | \name{import_list}
4 | \alias{import_list}
5 | \title{Import list of data frames}
6 | \usage{
7 | import_list(
8 | file,
9 | setclass = getOption("rio.import.class", "data.frame"),
10 | which,
11 | rbind = FALSE,
12 | rbind_label = "_file",
13 | rbind_fill = TRUE,
14 | ...
15 | )
16 | }
17 | \arguments{
18 | \item{file}{A character string containing a single file name for a multi-object file (e.g., Excel workbook, zip file, tar archive, or HTML file), or a vector of file paths for multiple files to be imported.}
19 |
20 | \item{setclass}{An optional character vector specifying one or more classes
21 | to set on the import. By default, the return object is always a
22 | \dQuote{data.frame}. Allowed values include \dQuote{tbl_df}, \dQuote{tbl}, or
23 | \dQuote{tibble} (if using tibble), \dQuote{arrow}, \dQuote{arrow_table} (if using arrow table; the suggested package \code{arrow} must be installed) or \dQuote{data.table} (if using
24 | data.table). Other values are ignored, such that a data.frame is returned.
25 | The parameter takes precedents over parameters in \dots which set a different class.}
26 |
27 | \item{which}{If \code{file} is a single file path, this specifies which objects should be extracted (passed to \code{\link[=import]{import()}}'s \code{which} argument). Ignored otherwise.}
28 |
29 | \item{rbind}{A logical indicating whether to pass the import list of data frames through \code{\link[data.table:rbindlist]{data.table::rbindlist()}}.}
30 |
31 | \item{rbind_label}{If \code{rbind = TRUE}, a character string specifying the name of a column to add to the data frame indicating its source file.}
32 |
33 | \item{rbind_fill}{If \code{rbind = TRUE}, a logical indicating whether to set the \code{fill = TRUE} (and fill missing columns with \code{NA}).}
34 |
35 | \item{\dots}{Additional arguments passed to \code{\link[=import]{import()}}. Behavior may be unexpected if files are of different formats.}
36 | }
37 | \value{
38 | If \code{rbind=FALSE} (the default), a list of a data frames. Otherwise, that list is passed to \code{\link[data.table:rbindlist]{data.table::rbindlist()}} with \code{fill = TRUE} and returns a data frame object of class set by the \code{setclass} argument; if this operation fails, the list is returned.
39 | }
40 | \description{
41 | Use \code{\link[=import]{import()}} to import a list of data frames from a vector of file names or from a multi-object file (Excel workbook, .Rdata file, compressed directory in a zip file or tar archive, or HTML file)
42 | }
43 | \details{
44 | When file is a vector of file paths and any files are missing, those files are ignored (with warnings) and this function will not raise any error. For compressed files, the file name must also contain information about the file format of all compressed files, e.g. \code{files.csv.zip} for this function to work.
45 | }
46 | \section{Trust}{
47 | For serialization formats (.R, .RDS, and .RData), please note that you should only load these files from trusted sources. It is because these formats are not necessarily for storing rectangular data and can also be used to store many things, e.g. code. Importing these files could lead to arbitary code execution. Please read the security principles by the R Project (Plummer, 2024). When importing these files via \code{rio}, you should affirm that you trust these files, i.e. \code{trust = TRUE}. See example below. If this affirmation is missing, the current version assumes \code{trust} to be true for backward compatibility and a deprecation notice will be printed. In the next major release (2.0.0), you must explicitly affirm your trust when importing these files.
48 | }
49 |
50 | \section{Which}{
51 | For compressed archives (zip and tar, where a compressed file can contain multiple files), it is possible to come to a situation where the parameter \code{which} is used twice to indicate two different concepts. For example, it is unclear for \code{.xlsx.zip}whether \code{which} refers to the selection of an exact file in the archive or the selection of an exact sheet in the decompressed Excel file. In these cases, \code{rio} assumes that \code{which} is only used for the selection of file. After the selection of file with \code{which}, \code{rio} will return the first item, e.g. the first sheet.
52 |
53 | Please note, however, \code{.gz} and \code{.bz2} (e.g. \code{.xlsx.gz}) are compressed, but not archive format. In those cases, \code{which} is used the same way as the non-compressed format, e.g. selection of sheet for Excel.
54 | }
55 |
56 | \examples{
57 | ## For demo, a temp. file path is created with the file extension .xlsx
58 | xlsx_file <- tempfile(fileext = ".xlsx")
59 | export(
60 | list(
61 | mtcars1 = mtcars[1:10, ],
62 | mtcars2 = mtcars[11:20, ],
63 | mtcars3 = mtcars[21:32, ]
64 | ),
65 | xlsx_file
66 | )
67 |
68 | # import a single file from multi-object workbook
69 | import(xlsx_file, sheet = "mtcars1")
70 | # import all worksheets, the return value is a list
71 | import_list(xlsx_file)
72 |
73 | # import and rbind all worksheets, the return value is a data frame
74 | import_list(xlsx_file, rbind = TRUE)
75 | }
76 | \references{
77 | Plummer, M (2024). Statement on CVE-2024-27322. \url{https://blog.r-project.org/2024/05/10/statement-on-cve-2024-27322/}
78 | }
79 | \seealso{
80 | \code{\link[=import]{import()}}, \code{\link[=export_list]{export_list()}}, \code{\link[=export]{export()}}
81 | }
82 |
--------------------------------------------------------------------------------
/man/install_formats.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/suggestions.R
3 | \name{install_formats}
4 | \alias{install_formats}
5 | \alias{show_unsupported_formats}
6 | \title{Install rio's \sQuote{Suggests} Dependencies}
7 | \usage{
8 | install_formats(...)
9 |
10 | show_unsupported_formats()
11 | }
12 | \arguments{
13 | \item{\dots}{Additional arguments passed to \code{\link[utils:install.packages]{utils::install.packages()}}.}
14 | }
15 | \value{
16 | For \code{show_unsupported_formats()}, if there is any missing unsupported formats, it return TRUE invisibly; otherwise FALSE. For \code{install_formats()} it returns TRUE invisibly if the installation is succuessful; otherwise errors.
17 | }
18 | \description{
19 | Not all suggested packages are installed by default. These packages are not installed or loaded by default in order to create a slimmer and faster package build, install, and load. Use \code{show_unsupported_formats()} to check all unsupported formats. \code{install_formats()} installs all missing \sQuote{Suggests} dependencies for rio that expand its support to the full range of support import and export formats.
20 | }
21 | \examples{
22 | \donttest{
23 | if (interactive()) {
24 | install_formats()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/man/rio.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/rio.R
3 | \docType{package}
4 | \name{rio}
5 | \alias{rio-package}
6 | \alias{rio}
7 | \title{A Swiss-Army Knife for Data I/O}
8 | \description{
9 | The aim of rio is to make data file input and output as easy as possible. \code{\link[=export]{export()}} and \code{\link[=import]{import()}} serve as a Swiss-army knife for painless data I/O for data from almost any file format by inferring the data structure from the file extension, natively reading web-based data sources, setting reasonable defaults for import and export, and relying on efficient data import and export packages. An additional convenience function, \code{\link[=convert]{convert()}}, provides a simple method for converting between file types.
10 |
11 | Note that some of rio's functionality is provided by \sQuote{Suggests} dependendencies, meaning they are not installed by default. Use \code{\link[=install_formats]{install_formats()}} to make sure these packages are available for use.
12 | }
13 | \examples{
14 | # export
15 | library("datasets")
16 | export(mtcars, csv_file <- tempfile(fileext = ".csv")) # comma-separated values
17 | export(mtcars, rds_file <- tempfile(fileext = ".rds")) # R serialized
18 | export(mtcars, sav_file <- tempfile(fileext = ".sav")) # SPSS
19 |
20 | # import
21 | x <- import(csv_file)
22 | y <- import(rds_file)
23 | z <- import(sav_file)
24 |
25 | # convert sav (SPSS) to dta (Stata)
26 | convert(sav_file, dta_file <- tempfile(fileext = ".dta"))
27 |
28 | # cleanup
29 | unlink(c(csv_file, rds_file, sav_file, dta_file))
30 |
31 | }
32 | \references{
33 | \href{https://cran.r-project.org/package=datamods}{datamods} provides Shiny modules for importing data via \code{rio}.
34 |
35 | \href{https://github.com/Stan125/GREA}{GREA} provides an RStudio add-in to import data using rio.
36 | }
37 | \seealso{
38 | \code{\link[=import]{import()}}, \code{\link[=import_list]{import_list()}}, \code{\link[=export]{export()}}, \code{\link[=export_list]{export_list()}}, \code{\link[=convert]{convert()}}, \code{\link[=install_formats]{install_formats()}}
39 | }
40 | \author{
41 | \strong{Maintainer}: Chung-hong Chan \email{chainsawtiney@gmail.com} (\href{https://orcid.org/0000-0002-6232-7530}{ORCID})
42 |
43 | Authors:
44 | \itemize{
45 | \item Jason Becker \email{jason@jbecker.co}
46 | \item David Schoch \email{david@schochastics.net} (\href{https://orcid.org/0000-0003-2952-4812}{ORCID})
47 | \item Thomas J. Leeper \email{thosjleeper@gmail.com} (\href{https://orcid.org/0000-0003-4097-6326}{ORCID})
48 | }
49 |
50 | Other contributors:
51 | \itemize{
52 | \item Geoffrey CH Chan \email{gefchchan@gmail.com} [contributor]
53 | \item Christopher Gandrud [contributor]
54 | \item Andrew MacDonald [contributor]
55 | \item Ista Zahn [contributor]
56 | \item Stanislaus Stadlmann [contributor]
57 | \item Ruaridh Williamson \email{ruaridh.williamson@gmail.com} [contributor]
58 | \item Patrick Kennedy [contributor]
59 | \item Ryan Price \email{ryapric@gmail.com} [contributor]
60 | \item Trevor L Davis \email{trevor.l.davis@gmail.com} [contributor]
61 | \item Nathan Day \email{nathancday@gmail.com} [contributor]
62 | \item Bill Denney \email{wdenney@humanpredictions.com} (\href{https://orcid.org/0000-0002-5759-428X}{ORCID}) [contributor]
63 | \item Alex Bokov \email{alex.bokov@gmail.com} (\href{https://orcid.org/0000-0002-0511-9815}{ORCID}) [contributor]
64 | \item Hugo Gruson (\href{https://orcid.org/0000-0002-4094-1476}{ORCID}) [contributor]
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/po/R-rio.pot:
--------------------------------------------------------------------------------
1 | msgid ""
2 | msgstr ""
3 | "Project-Id-Version: rio 0.5.27\n"
4 | "POT-Creation-Date: 2021-06-18 09:36\n"
5 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
6 | "Last-Translator: FULL NAME \n"
7 | "Language-Team: LANGUAGE \n"
8 | "MIME-Version: 1.0\n"
9 | "Content-Type: text/plain; charset=CHARSET\n"
10 | "Content-Transfer-Encoding: 8bit\n"
11 |
12 |
13 | msgid "The following arguments were ignored for"
14 | msgstr ""
15 |
16 | msgid ":"
17 | msgstr ""
18 |
19 | msgid ","
20 | msgstr ""
21 |
22 | msgid "condition"
23 | msgstr ""
24 |
25 | msgid "File compression failed for %s!"
26 | msgstr ""
27 |
28 | msgid "Zip archive contains multiple files. Attempting first file."
29 | msgstr ""
30 |
31 | msgid "Tar archive contains multiple files. Attempting first file."
32 | msgstr ""
33 |
34 | msgid "'outfile' is missing with no default"
35 | msgstr ""
36 |
37 | msgid "Must specify 'file' and/or 'format'"
38 | msgstr ""
39 |
40 | msgid "'x' is not a data.frame or matrix"
41 | msgstr ""
42 |
43 | msgid "'x' must be a list. Perhaps you want export()?"
44 | msgstr ""
45 |
46 | msgid "'file' must be a character vector"
47 | msgstr ""
48 |
49 | msgid "'file' must have a %s placehold"
50 | msgstr ""
51 |
52 | msgid "All elements of 'x' must be named or all must be unnamed"
53 | msgstr ""
54 |
55 | msgid "Names of elements in 'x' are not unique"
56 | msgstr ""
57 |
58 | msgid "'file' must be same length as 'x', or a single pattern with a %s placeholder"
59 | msgstr ""
60 |
61 | msgid "File names are not unique"
62 | msgstr ""
63 |
64 | msgid "Export failed for element %d, filename: %s"
65 | msgstr ""
66 |
67 | msgid "data.table::fwrite() does not support writing to connections. Using utils::write.table() instead."
68 | msgstr ""
69 |
70 | msgid "Columns:"
71 | msgstr ""
72 |
73 | msgid "'x' must be a data.frame, list, or environment"
74 | msgstr ""
75 |
76 | msgid "%s format not supported. Consider using the '%s()' function"
77 | msgstr ""
78 |
79 | msgid "Import support for the %s format is exported by the %s package. Run 'library(%s)' then try again."
80 | msgstr ""
81 |
82 | msgid "Format not supported"
83 | msgstr ""
84 |
85 | msgid "'x' is not a data.frame"
86 | msgstr ""
87 |
88 | msgid "No such file"
89 | msgstr ""
90 |
91 | msgid "'data.table = TRUE' argument overruled. Using setclass = '%s'"
92 | msgstr ""
93 |
94 | msgid "Import failed for %s"
95 | msgstr ""
96 |
97 | msgid "Import failed for %s from %s"
98 | msgstr ""
99 |
100 | msgid "Attempt to rbindlist() the data did not succeed. List returned instead."
101 | msgstr ""
102 |
103 | msgid "data.table::fread() does not support reading from connections. Using utils::read.table() instead."
104 | msgstr ""
105 |
106 | msgid "Ambiguous file format ('.dat'), but attempting 'data.table::fread(\"%s\")'"
107 | msgstr ""
108 |
109 | msgid "Import of fixed-width format data requires a 'widths' argument. See ? read.fwf()."
110 | msgstr ""
111 |
112 | msgid "File imported using load. Arguments to '...' ignored."
113 | msgstr ""
114 |
115 | msgid "Dump file contains multiple objects. Returning first object."
116 | msgstr ""
117 |
118 | msgid "File imported using readRDS. Arguments to '...' ignored."
119 | msgstr ""
120 |
121 | msgid "Rdata file contains multiple objects. Returning first object."
122 | msgstr ""
123 |
124 | msgid "Import of Fortran format data requires a 'style' argument. See ? utils::read.fortran()."
125 | msgstr ""
126 |
127 | msgid "The following arguments were ignored for read_ods:"
128 | msgstr ""
129 |
130 | msgid "Requested table exceeds number of tables found in file ("
131 | msgstr ""
132 |
133 | msgid ")!"
134 | msgstr ""
135 |
136 | msgid "Unrecognized file format. Try specifying with the format argument."
137 | msgstr ""
138 |
139 | msgid "'file' is not a string"
140 | msgstr ""
141 |
142 | msgid "'file' has no extension"
143 | msgstr ""
144 |
145 | msgid "last record incomplete, %d line discarded"
146 | msgid_plural "last record incomplete, %d lines discarded"
147 | msgstr[0] ""
148 | msgstr[1] ""
149 |
--------------------------------------------------------------------------------
/rio.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: No
4 | SaveWorkspace: No
5 | AlwaysSaveHistory: Default
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 4
10 | Encoding: UTF-8
11 |
12 | RnwWeave: Sweave
13 | LaTeX: XeLaTeX
14 |
15 | LineEndingConversion: Posix
16 |
17 | BuildType: Package
18 | PackageUseDevtools: Yes
19 | PackageInstallArgs: --no-multiarch --with-keep.source
20 | PackageRoxygenize: rd,namespace,vignette
21 |
--------------------------------------------------------------------------------
/starwars.csv:
--------------------------------------------------------------------------------
1 | Name,homeworld,species
2 | Luke Skywalker,Tatooine,Human
3 | C-3PO,Tatooine,Human
4 | R2-D2,Alderaan,Human
5 | Darth Vader,Tatooine,Human
6 | Leia Organa,Tatooine,Human
7 | Owen Lars,Tatooine,Human
8 | Beru Whitesun lars,Stewjon,Human
9 | R5-D4,Tatooine,Human
10 | Biggs Darklighter,Kashyyyk,Wookiee
11 | Obi-Wan Kenobi,Corellia,Human
12 |
--------------------------------------------------------------------------------
/starwars.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gesistsa/rio/f1094bf636f95f5dfcb05408d2ca0960fa792c8e/starwars.xlsx
--------------------------------------------------------------------------------
/tests/testdata/br-in-header.html:
--------------------------------------------------------------------------------
1 |
2 |