readwritesqlite

An R package that enhances writing and reading data to and from SQLite databases

https://github.com/poissonconsulting/readwritesqlite

Science Score: 26.0%

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

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

Keywords

cran dbi log metadata posixct r read rstats sfc sqlite units write

Keywords from Contributors

chk species-sensitivity-distribution assertion checkr fish ecotoxicology bc ssd water-quality-guideline derived-parameters
Last synced: 6 months ago · JSON representation

Repository

An R package that enhances writing and reading data to and from SQLite databases

Basic Info
Statistics
  • Stars: 37
  • Watchers: 4
  • Forks: 1
  • Open Issues: 8
  • Releases: 5
Topics
cran dbi log metadata posixct r read rstats sfc sqlite units write
Created about 7 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Support

README.Rmd

---
output: github_document
---



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

# readwritesqlite 

[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/poissonconsulting/readwritesqlite/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/readwritesqlite/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/readwritesqlite/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/readwritesqlite)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)
[![CRAN status](https://www.r-pkg.org/badges/version/readwritesqlite)](https://cran.r-project.org/package=readwritesqlite)
![CRAN Downloads](http://cranlogs.r-pkg.org/badges/readwritesqlite)


# readwritesqlite

SQLite databases are a simple, powerful way to validate, query and store related data frames particularly when used with the RSQLite package.
However, current solutions do not preserve (or check) meta data, log changes or provide particularly useful error messages.

`readwritesqlite` is an R package that by default

- preserves (and subsequently checks) the following metadata
  - the class for logical, Date and hms columns
  - the levels for factors and ordered factors
  - the time zone for POSIXct columns
  - the units for unit columns
  - the projection for sfc columns
  - the sf column for sf objects
- logs 
    - the date time
    - system user
    - table creation and data insertion or deletion
- provides informative error messages if
    - columns are missing
    - NOT NULL columns contain missing values
    - PRIMARY KEY column values in the input data are not unique
    
`readwritesqlite` also allows the user to 

- write environments (or named lists) of data frames (useful for populating databases)
- delete existing data (and meta data) before writing (useful for converting an existing database)
- replace existing data which causes unique or primary key conflicts (useful for updating databases)
- confirm data can be written without committing any changes (useful for checking data)
- check all existing tables are written to (useful for data transfers)
- rearrange and add levels for factors and add levels for ordered factors
- initialize the meta data for a new table by writing a data frame or sf data frame with no rows but logical, Date, factor, ordered, POSIXct, sfc or unit columns (useful for creating an empty database with additional informative checks)

`readwritesqlite` provides all these features through its `rws_write()` and `rws_read()` functions.

The `rws_query()` function allows the user to pass a SQL query.
By default, the metadata (except the setting of the sf column) is, if unambiguously defined, preserved for each column in the final query.
To enable this functionality the user should ensure that a) columns in tables which will be referenced in the same query should have different names or identical metadata and b) column names in the final query should match those in the referenced base tables.

The init, meta and log data are stored in separate tables from the main data which means that they do not interfere with other ways of interacting with a SQLite database.

## Installation

To install the latest release from [CRAN](https://cran.r-project.org)
```r
install.packages("readwritesqlite")
```

To install the developmental version from [GitHub](https://github.com/poissonconsulting/readwritesqlite)
```r
# install.packages("remotes")
remotes::install_github("poissonconsulting/readwritesqlite")
```

## Demonstration

Key attribute information is preserved for many classes.
```{r}
library(readwritesqlite)

# for nicer printing of data frames
library(tibble)
library(sf)

conn <- rws_connect()

rws_data <- readwritesqlite::rws_data
rws_data

rws_write(rws_data, exists = FALSE, conn = conn)

rws_read_table("rws_data", conn = conn)
```

The attribute information is stored in the metadata table
```{r}
rws_read_meta(conn = conn)
```

The user can add descriptions if they wish.
```{r}
rws_describe_meta("rws_data", "posixct", "The time of a visit", conn = conn)
rws_describe_meta("rws_data", "units", "The site length.", conn = conn)
rws_read_meta(conn = conn)
```

The log provides a record of data changes that have been made using readwritesqlite.
``` r
rws_read_log(conn = conn)
#> # A tibble: 2 x 5
#>   DateTimeUTCLog      UserLog TableLog CommandLog NRowLog
#>                                
#> 1 2019-07-07 16:05:10 joe     RWS_DATA CREATE           0
#> 2 2019-07-07 16:05:11 joe     RWS_DATA INSERT           3
```

Don't forget to disconnect when done.
```{r}
rws_disconnect(conn)
```

## Information

For more information on using `readwritesqlite` see the vignette [using-readwritesqlite](https://poissonconsulting.github.io/readwritesqlite/articles/using-readwritesqlite.html).

## Contribution

Please report any [issues](https://github.com/poissonconsulting/readwritesqlite/issues).

[Pull requests](https://github.com/poissonconsulting/readwritesqlite/pulls) are always welcome.

## Code of Conduct

Please note that the readwritesqlite project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.

Owner

  • Name: Poisson Consulting Ltd.
  • Login: poissonconsulting
  • Kind: organization
  • Email: software@poissonconsulting.ca
  • Location: Nelson, BC, Canada

Computational Biology and Statistical Ecology

GitHub Events

Total
  • Create event: 14
  • Issues event: 1
  • Release event: 1
  • Watch event: 2
  • Issue comment event: 29
  • Push event: 66
  • Pull request event: 30
Last Year
  • Create event: 14
  • Issues event: 1
  • Release event: 1
  • Watch event: 2
  • Issue comment event: 29
  • Push event: 66
  • Pull request event: 30

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 360
  • Total Committers: 8
  • Avg Commits per committer: 45.0
  • Development Distribution Score (DDS): 0.222
Past Year
  • Commits: 48
  • Committers: 2
  • Avg Commits per committer: 24.0
  • Development Distribution Score (DDS): 0.479
Top Committers
Name Email Commits
Joe Thorley j****e@p****a 280
Kirill Müller k****r 25
Duncan Kennedy d****n@p****a 23
Evan e****i@g****m 22
Seb Dalgarno s****b@p****a 3
Nadine Hussein n****3@g****m 3
Ayla Pearson a****3@g****m 2
Mowahid Latif m****f@M****l 2
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 33
  • Total pull requests: 37
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 19 days
  • Total issue authors: 9
  • Total pull request authors: 6
  • Average comments per issue: 1.61
  • Average comments per pull request: 0.22
  • Merged pull requests: 34
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 27
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.15
  • Merged pull requests: 27
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • joethorley (18)
  • evanamiesgalonski (5)
  • krlmlr (3)
  • aylapear (2)
  • edzer (1)
  • NewGraphEnvironment (1)
  • sebdalgarno (1)
  • D3SL (1)
  • dusadrian (1)
Pull Request Authors
  • krlmlr (25)
  • dunkenwg (4)
  • MowahidLatif (3)
  • joethorley (2)
  • evanamiesgalonski (2)
  • nadinehussein (1)
Top Labels
Issue Labels
Timeline: Soon (5) Type: Feature (5) Difficulty: Intermediate (4) Effort: Medium (4) Importance: High (3) Importance: Medium (3) Difficulty: Advanced (2) Type: Bug (1) Timeline: Now (1) Effort: Small (1) Type: Refactor (1) Effort: Large (1)
Pull Request Labels

Packages

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

Enhanced Reading and Writing for 'SQLite' Databases

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 4
  • Downloads: 263 Last month
Rankings
Stargazers count: 8.1%
Dependent repos count: 14.6%
Forks count: 21.0%
Average: 22.1%
Dependent packages count: 28.8%
Downloads: 38.1%
Maintainers (1)
Last synced: 7 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.6 depends
  • DBI * imports
  • RSQLite * imports
  • chk * imports
  • crayon * imports
  • glue * imports
  • hms * imports
  • lifecycle * imports
  • rlang * imports
  • sf * imports
  • tibble * imports
  • covr * suggests
  • knitr * suggests
  • pool * suggests
  • rmarkdown * suggests
  • testthat * suggests
  • units * suggests
.github/workflows/R-CMD-check.yaml actions
  • 8398a7/action-slack v3.0.0 composite
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • actions/upload-artifact master composite
  • r-lib/actions/setup-pandoc master composite
  • r-lib/actions/setup-r master composite
  • r-lib/actions/setup-tinytex v2 composite
.github/workflows/coverage.yaml actions
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc master composite
  • r-lib/actions/setup-r master composite
.github/workflows/pkgdown.yaml actions
  • 8398a7/action-slack v3.0.0 composite
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc master composite
  • r-lib/actions/setup-r master composite