diff --git a/.Rbuildignore b/.Rbuildignore index b34d40f..fbf080d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -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$ diff --git a/.github/workflows/R-CMD-check.yml b/.github/workflows/R-CMD-check.yml new file mode 100644 index 0000000..4d03beb --- /dev/null +++ b/.github/workflows/R-CMD-check.yml @@ -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 diff --git a/.gitignore b/.gitignore index 6040326..57758ac 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,5 @@ rsconnect/ # machine .DS_Store +/doc/ +/Meta/ diff --git a/DESCRIPTION b/DESCRIPTION index 2ec9627..d1002f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ 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", @@ -9,11 +9,11 @@ Authors@R: role = c("aut", "cre"), email = "dereck@mezquita.io", comment = c(ORCID = "0000-0002-9307-6762")) +Author: Dereck Mezquita [aut, cre] (0000-0002-9307-6762) Maintainer: Dereck Mezquita -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) @@ -23,5 +23,4 @@ Suggests: rmarkdown, box, rcmdcheck, - lintr, - data.table + data.table \ No newline at end of file diff --git a/LICENSE b/LICENSE index 91325b8..f484b4e 100644 --- a/LICENSE +++ b/LICENSE @@ -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 @@ -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. \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index d6414f5..cff2915 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,3 +17,4 @@ export(enum) export(fun) export(interface) export(type.frame) +importFrom(utils,head) diff --git a/NEWS.md b/NEWS.md index ec6a2d0..8c22d24 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. \ No newline at end of file diff --git a/R/fun.R b/R/fun.R index 4050f88..870879b 100644 --- a/R/fun.R +++ b/R/fun.R @@ -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 diff --git a/R/type.frame.R b/R/type.frame.R index 73fb05c..ee8f54e 100644 --- a/R/type.frame.R +++ b/R/type.frame.R @@ -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") } @@ -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 @@ -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 @@ -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)) diff --git a/README.Rmd b/README.Rmd index b1f3a84..0e8a646 100644 --- a/README.Rmd +++ b/README.Rmd @@ -20,10 +20,13 @@ knitr::opts_chunk$set( # interface -[![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) 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. @@ -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 diff --git a/README.md b/README.md index a16156c..0ea9e03 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,17 @@ +[![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) The `interface` package provides a system for defining and implementing @@ -130,7 +137,7 @@ print(john_student) #> scores: Science #> scores: 95 #> scores: 88 -#> scholarship: +#> scholarship: #> street: 123 Main St #> city: Small town #> postal_code: 12345 @@ -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. diff --git a/inst/CITATION b/inst/CITATION new file mode 100644 index 0000000..2329507 --- /dev/null +++ b/inst/CITATION @@ -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" + ) +) \ No newline at end of file diff --git a/man/cash-set-.typed_frame.Rd b/man/cash-set-.typed_frame.Rd index 535a84d..6325da2 100644 --- a/man/cash-set-.typed_frame.Rd +++ b/man/cash-set-.typed_frame.Rd @@ -4,12 +4,12 @@ \alias{$<-.typed_frame} \title{Modify a typed data frame using $} \usage{ -\method{$}{typed_frame}(x, name) <- value +\method{$}{typed_frame}(x, col_name) <- value } \arguments{ \item{x}{A typed data frame.} -\item{name}{The name of the column to modify or add.} +\item{col_name}{The name of the column to modify or add.} \item{value}{The new value to assign.} } diff --git a/man/fun.Rd b/man/fun.Rd index 483c9c4..500fb10 100644 --- a/man/fun.Rd +++ b/man/fun.Rd @@ -7,11 +7,7 @@ fun(...) } \arguments{ -\item{...}{Named arguments defining the function parameters and their types.} - -\item{return}{The expected return type(s).} - -\item{impl}{The function implementation.} +\item{...}{Named arguments defining the function parameters and their types, including 'return' for the expected return type(s) and 'impl' for the function implementation.} } \value{ A typed function that enforces type constraints on its parameters and return value. @@ -22,6 +18,7 @@ Defines a function with specified parameter types and return type. Ensures that \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 diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index f1e38b3..a4d70fa 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -12,6 +12,8 @@ navbar: left: [home, reference, articles, donate] right: [github, youtube, search, website, website2] components: + citation: + text: Citation articles: text: Articles menu: