Skip to content

Commit

Permalink
RPKG-5: CRAN submission (#22)
Browse files Browse the repository at this point in the history
* Version bump.

* Docs adjustments and citation.

* Mandatory author field.

* Fix urls.

* R cmd check workflow.

* Fix citation.

* Update ignore.

* Check build on newer vresions.

* Rbuild ignore more files.

* Ignore more.

* Don't need lazy data if no data.

* Citation stipulation.

* Fix workflow?

* Test different version.

* News update.

* Need pandoc to test.

* Typo.

* New badges and test on linux too.

* Better workflow with schedule.

* Badges.
  • Loading branch information
dereckmezquita authored Aug 26, 2024
1 parent 8bc5c1c commit e273a6d
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 38 deletions.
11 changes: 11 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
^README\.html$
^assets$
^docs$
^pkgdown$
.git
.github
.gitignore
.lintr
README.Rmd
TODO.md
^.*\.Rproj$
^\.Rproj\.user$
renv/
^renv$
^renv\.lock$
dev-docs/
dev/
research/
.Rprofile
tests/
^doc$
^Meta$
61 changes: 61 additions & 0 deletions .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: R CMD check

on:
push:
branches: [master]
pull_request:
branches: [master]
schedule:
- cron: '0 0 * * 0' # Run every Sunday at midnight UTC

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (R-${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: '4.1.0'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: '4.1.0'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-latest, r: '4.1.0'}
- {os: ubuntu-latest, r: 'release'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ rsconnect/

# machine
.DS_Store
/doc/
/Meta/
11 changes: 5 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Package: interface
Type: Package
Title: A runtime type system for R; interfaces, enums, typed data.frames/data.tables and functions
Version: 0.0.41
Title: Runtime Type System for R
Version: 0.1.0
URL: https://github.com/dereckmezquita/interface
Authors@R:
person(given = "Dereck",
family = "Mezquita",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-9307-6762"))
Author: Dereck Mezquita [aut, cre] (0000-0002-9307-6762)
Maintainer: Dereck Mezquita <[email protected]>
Description: A runtime type system for R, define and implement interfaces, enums, typed data.frames/data.tables, and typed functions with zero dependencies
Description: Provides a runtime type system for R, allowing users to define and implement interfaces, enums, typed data.frame/data.table, as well as typed functions. This package enables stricter type checking and validation, improving code structure, robustness and reliability in R programming.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 7.3.2
Depends: R (>= 4.1.0)
Expand All @@ -23,5 +23,4 @@ Suggests:
rmarkdown,
box,
rcmdcheck,
lintr,
data.table
data.table
12 changes: 3 additions & 9 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License with Citation Requirement
MIT License

Copyright (c) 2024 Dereck Mezquita, Dereck's Projects
Copyright (c) 2024 Dereck Mezquita

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -12,16 +12,10 @@ furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

Additionally, any use of this Software in commercial, academic or research settings
must include appropriate citation. The required citation is:

Mezquita, D. (2024). interface. https://github.com/dereckmezquita/interface.
ORCID: 0000-0002-9307-6762

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export(enum)
export(fun)
export(interface)
export(type.frame)
importFrom(utils,head)
22 changes: 22 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,29 @@
2. Added support for optional runtime type checking.
3. Included support for nested interfaces and custom validation functions.
4. Created comprehensive documentation and vignettes.
5. Implemented enum functionality for defining enumerated types.
6. Added typed functions with strict type constraints.
7. Implemented typed data frames and data tables with column type constraints and row validation.

## IMPROVEMENTS

1. Enhanced package structure and organization.
2. Improved error handling and informative error messages.
3. Optimized performance for type checking operations.

## DOCUMENTATION

1. Created detailed vignettes for package usage and examples.
2. Improved function documentation with more examples and clearer explanations.
3. Added a README with installation instructions and quick start guide.

## DEVELOPMENT

1. Set up continuous integration with GitHub Actions.
2. Implemented comprehensive test suite using testthat.
3. Ensured CRAN policy compliance.

## NOTES

1. This is the first release of the `interface` package.
2. The package is compatible with R versions 4.1.0 and above.
5 changes: 2 additions & 3 deletions R/fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
#' @description
#' Defines a function with specified parameter types and return type. Ensures that the function's arguments and return value adhere to the specified types.
#'
#' @param ... Named arguments defining the function parameters and their types.
#' @param return The expected return type(s).
#' @param impl The function implementation.
#' @param ... Named arguments defining the function parameters and their types, including 'return' for the expected return type(s) and 'impl' for the function implementation.
#' @return A typed function that enforces type constraints on its parameters and return value.
#' @details
#' The `fun` function allows you to define a function with strict type checking for its parameters and return value.
#' This ensures that the function receives arguments of the correct types and returns a value of the expected type.
#' The 'return' and 'impl' arguments should be included in the ... parameter list.
#'
#' @examples
#' # Define a typed function that adds two numbers
Expand Down
13 changes: 7 additions & 6 deletions R/type.frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ wrap_fun_in_all <- function(user_fun) {
#' Allows modifying a typed data frame using the $ operator, with validation checks.
#'
#' @param x A typed data frame.
#' @param name The name of the column to modify or add.
#' @param col_name The name of the column to modify or add.
#' @param value The new value to assign.
#' @return The modified typed data frame.
#' @export
`$<-.typed_frame` <- function(x, name, value) {
`$<-.typed_frame` <- function(x, col_name, value) {
# Check if adding new columns is allowed
if (attr(x, "freeze_n_cols") && !(name %in% names(x))) {
if (attr(x, "freeze_n_cols") && !(col_name %in% names(x))) {
stop("Adding new columns is not allowed when freeze_n_cols is TRUE")
}

Expand All @@ -287,8 +287,8 @@ wrap_fun_in_all <- function(user_fun) {
}

# Check for NA values
if (!attr(value, "allow_na") && any(is.na(value))) {
handle_violation("NA values are not allowed", attr(value, "on_violation"))
if (!attr(x, "allow_na") && any(is.na(value))) {
handle_violation("NA values are not allowed", attr(x, "on_violation"))
}

# TODO: really review if a row callback is useful at all
Expand All @@ -315,6 +315,7 @@ wrap_fun_in_all <- function(user_fun) {
#'
#' @param x A typed data frame.
#' @param ... Additional arguments passed to print.
#' @importFrom utils head
#' @export
print.typed_frame <- function(x, ...) {
# Determine the base frame type
Expand All @@ -339,7 +340,7 @@ print.typed_frame <- function(x, ...) {
cat(sprintf(" On violation : %s\n", attr(x, "on_violation")))

cat("\nData Preview:\n")
print(as.data.frame(head(x, 5)))
print(as.data.frame(utils::head(x, 5)))

if (nrow(x) > 5) {
cat(sprintf("\n... with %d more rows\n", nrow(x) - 5))
Expand Down
17 changes: 13 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ knitr::opts_chunk$set(
# interface

<!-- badges: start -->
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Travis build
status](https://travis-ci.org/dereckmezquita/kucoin.svg?branch=master)](https://travis-ci.org/dereckmezquita/kucoin)
[![R-CMD-check](https://github.com/dereckmezquita/interface/workflows/R-CMD-check/badge.svg)](https://github.com/dereckmezquita/interface/actions)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/interface)](https://CRAN.R-project.org/package=interface)
[![GitHub version](https://img.shields.io/github/r-package/v/dereckmezquita/interface?label=GitHub)](https://github.com/dereckmezquita/interface)
[![R-CMD-check](https://github.com/dereckmezquita/interface/workflows/R-CMD-check/badge.svg)](https://github.com/dereckmezquita/interface/actions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://cranlogs.r-pkg.org/badges/interface)](https://cran.r-project.org/package=interface)
<!-- badges: end -->

The `interface` package provides a system for defining and implementing interfaces in R, with runtime type checking, bringing some of the benefits of statically-typed languages to R with zero dependencies.
Expand Down Expand Up @@ -325,3 +328,9 @@ try(car1$make$value <- "Honda")
## Conclusion

The `interface` package provides powerful tools for ensuring type safety and validation in R. By defining interfaces, typed functions, and typed data frames, you can create robust and reliable data structures and functions with strict type constraints. For more details, refer to the package documentation.

## Citation

If you use this package in your research or work, please cite it as:

Mezquita, D. (2024). interface: A Runtime Type System for R. R package version 0.1.0. https://github.com/dereckmezquita/interface
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@

<!-- badges: start -->

[![R-CMD-check](https://github.com/dereckmezquita/interface/workflows/R-CMD-check/badge.svg)](https://github.com/dereckmezquita/interface/actions)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Travis build
status](https://travis-ci.org/dereckmezquita/kucoin.svg?branch=master)](https://travis-ci.org/dereckmezquita/kucoin)
[![CRAN
status](https://www.r-pkg.org/badges/version/interface)](https://CRAN.R-project.org/package=interface)
[![GitHub
version](https://img.shields.io/github/r-package/v/dereckmezquita/interface?label=GitHub)](https://github.com/dereckmezquita/interface)
[![R-CMD-check](https://github.com/dereckmezquita/interface/workflows/R-CMD-check/badge.svg)](https://github.com/dereckmezquita/interface/actions)
[![License:
MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://cranlogs.r-pkg.org/badges/interface)](https://cran.r-project.org/package=interface)
<!-- badges: end -->

The `interface` package provides a system for defining and implementing
Expand Down Expand Up @@ -130,7 +137,7 @@ print(john_student)
#> scores: Science
#> scores: 95
#> scores: 88
#> scholarship: <environment: 0x1202f3d50>
#> scholarship: <environment: 0x1166d42c0>
#> street: 123 Main St
#> city: Small town
#> postal_code: 12345
Expand Down Expand Up @@ -430,3 +437,10 @@ and validation in R. By defining interfaces, typed functions, and typed
data frames, you can create robust and reliable data structures and
functions with strict type constraints. For more details, refer to the
package documentation.

## Citation

If you use this package in your research or work, please cite it as:

Mezquita, D. (2024). interface: A Runtime Type System for R. R package
version 0.1.0. <https://github.com/dereckmezquita/interface>
14 changes: 14 additions & 0 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bibentry(
bibtype = "Manual",
title = "interface: A Runtime Type System for R",
author = "Dereck Mezquita",
year = "2024",
note = "R package version 0.1.0",
url = "https://github.com/dereckmezquita/interface",
textVersion = paste(
"Mezquita, D. (2024).",
"interface: A Runtime Type System for R.",
"R package version 0.1.0.",
"https://github.com/dereckmezquita/interface"
)
)
4 changes: 2 additions & 2 deletions man/cash-set-.typed_frame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/fun.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ navbar:
left: [home, reference, articles, donate]
right: [github, youtube, search, website, website2]
components:
citation:
text: Citation
articles:
text: Articles
menu:
Expand Down

0 comments on commit e273a6d

Please sign in to comment.