From 7f919b8d02492b4b7298b9bd259e582223988c0a Mon Sep 17 00:00:00 2001 From: dereckmezquita Date: Mon, 26 Aug 2024 05:29:05 +0000 Subject: [PATCH] Built site for interface@0.1.0: f58de8a --- articles/intro-to-interface.html | 2 +- pkgdown.yml | 2 +- search.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/articles/intro-to-interface.html b/articles/intro-to-interface.html index 02b11cf..21e83f4 100644 --- a/articles/intro-to-interface.html +++ b/articles/intro-to-interface.html @@ -214,7 +214,7 @@

Nested Interfaces and Extend #> scores: Science #> scores: 95 #> scores: 88 -#> scholarship: <environment: 0x557469632048> +#> scholarship: <environment: 0x55f35203c408> #> street: 123 Main St #> city: Small town #> postal_code: 12345 diff --git a/pkgdown.yml b/pkgdown.yml index f1165d9..c6fabeb 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -4,7 +4,7 @@ pkgdown_sha: ~ articles: donate: donate.html intro-to-interface: intro-to-interface.html -last_built: 2024-08-26T05:23Z +last_built: 2024-08-26T05:28Z urls: reference: https://dereckmezquita.github.io/interface/reference article: https://dereckmezquita.github.io/interface/articles diff --git a/search.json b/search.json index 374e910..40fe0ae 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":[]},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description","dir":"","previous_headings":"1. Support for typed functions","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow defining functions typed arguments return values. require mechanism extending base R types.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas","dir":"","previous_headings":"1. Support for typed functions","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"","code":"function2 <- interface(\"function\", arg1 = \"numeric\", arg2 = \"character\", return = \"numeric\" ) # Implement the function f2 <- implement(function2, function(arg1, arg2) { return(arg1 + nchar(arg2)) })"},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-1","dir":"","previous_headings":"2. Support for generics with runtime enforcement","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow defining generic interface, allow one enforce types across data.frame columns example.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-1","dir":"","previous_headings":"2. Support for generics with runtime enforcement","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"","code":"# Define a interface with n character columns and m numeric columns Df <- interface(\"data.frame\", name = \"character\", height = \"numeric\", age = \"numeric\" ) # Implement the interface df1 <- implement(Df, data.frame( name = c(\"John\", \"Jane\"), height = c(5.8, 6.0), age = c(30, 25) ) ) # This should raise an error df1$age <- c(\"30\", \"25\")"},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-2","dir":"","previous_headings":"3. Allow for generics with either or types","what":"Description","title":"interface v0.1.0 (in development)","text":"Much way TypeScript allows Union Types, can allow Union Types interface package.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-2","dir":"","previous_headings":"3. Allow for generics with either or types","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"","code":"CharNumList <- interface(\"list\", value = c(\"character\", \"numeric\") ) # Implement the interface list1 <- implement(CharNumList, list(\"John\", 30)) Df <- interface(\"data.frame\", name = \"character\", height = c(\"numeric\", \"character\"), age = \"numeric\" )"},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-3","dir":"","previous_headings":"4. Implement Atomic Types","what":"Description","title":"interface v0.1.0 (in development)","text":"Create new way define atomic types, similar TypeScript’s type aliases. allow users define types single values instead lists .e. difference type interface TypeScript. way user even flexibility check length atomic type.","code":"type Cohort = \"alpha\" | \"beta\" | \"gamma\"; interface Person { name: string; age: number; cohort: Cohort; }"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-3","dir":"","previous_headings":"4. Implement Atomic Types","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"Create new function, type(), defines atomic types; instead returning list return vectors (since atomic types vectors R). Modify check_type() function handle new atomic types. Update implement() function return atomic values appropriate.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"example-usage","dir":"","previous_headings":"4. Implement Atomic Types","what":"Example Usage","title":"interface v0.1.0 (in development)","text":"","code":"Cohort <- type(\"Cohort\", c(\"alpha\", \"beta\", \"gamma\")) # by default the validate function only checks for membership cohort1 <- implement(Cohort, \"alpha\") # custom function for type checking Age <- type(\"Age\", function(x) { return(is.numeric(x) && x >= 0 && x <= 120 && length(x) == 1) }) # Use the atomic type john_age <- implement(Age, 30) print(john_age) # Should print a vector of length 1 # This should raise an error try(implement(Age, 150))"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"integration-with-existing-codebase","dir":"","previous_headings":"4. Implement Atomic Types","what":"Integration with Existing Codebase","title":"interface v0.1.0 (in development)","text":"Add new file R/type.R contain type() function related helpers. Modify R/implement.R handle atomic types differently interfaces. Update R/helpers.R include type checking atomic types. Add new print functions R/print.R handle atomic types.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-4","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow interfaces extend interfaces existing R types, similar inheritance object-oriented programming.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-4","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"Modify interface() function accept extends parameter. Update check_interface() function check properties extended interfaces types. Implement mechanism resolve property conflicts case multiple extensions.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"example-usage-1","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Example Usage","title":"interface v0.1.0 (in development)","text":"","code":"# Extend an existing interface Person <- interface(\"Person\", name = \"character\", age = \"numeric\" ) Employee <- interface(\"Employee\", extends = Person, job_title = \"character\", salary = \"numeric\" ) john <- implement(Employee, name = \"John Doe\", age = 30, job_title = \"Developer\", salary = 75000 ) # TODO: this needs more work # Extend an existing R type EnhancedDataFrame <- interface(\"EnhancedDataFrame\", extends = \"data.frame\", metadata = \"list\" ) my_df <- implement(EnhancedDataFrame, data.frame(x = 1:3, y = c(\"a\", \"b\", \"c\")), metadata = list(created_at = Sys.time()) )"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"integration-with-existing-codebase-1","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Integration with Existing Codebase","title":"interface v0.1.0 (in development)","text":"Modify R/interface.R handle extends parameter. Update R/helpers.R include extended property checking check_interface(). Add new test cases tests/testthat/test-interface.R extension functionality.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-5","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow interfaces specify method signatures, just properties.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-5","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"Extend interface() function accept method signatures. Implement mechanism check object implements required methods.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"example-usage-2","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Example Usage","title":"interface v0.1.0 (in development)","text":"","code":"Drawable <- interface(\"Drawable\", methods = list( draw = function() NULL ) ) Circle <- interface(\"Circle\", extends = Drawable, radius = \"numeric\", methods = list( area = function() NULL ) ) my_circle <- implement(Circle, radius = 5, draw = function() { return(cat(\"Drawing a circle\\n\")) }, area = function() { return(pi * self$radius ^ 2) } ) my_circle$draw() print(my_circle$area())"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"integration-with-existing-codebase-2","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Integration with Existing Codebase","title":"interface v0.1.0 (in development)","text":"Modify R/interface.R handle method signatures. Update R/implement.R check implement methods. Add new test cases tests/testthat/test-interface.R method functionality.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/donate.html","id":"support-my-work","dir":"Articles","previous_headings":"","what":"Support my work","title":"Donate","text":"find package useful, please consider supporting work cryptocurrency donation.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/donate.html","id":"bitcoin","dir":"Articles","previous_headings":"Support my work","what":"Bitcoin","title":"Donate","text":"bc1qgs4f6hhnzj8m2j05axgsf53k67kugps92qzr2k Copy","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/donate.html","id":"monero","dir":"Articles","previous_headings":"Support my work","what":"Monero","title":"Donate","text":"41wSUfpnhVUW5GnTKCyBBwVuokhkjMeepAVkKT1qv3HDhcZhTSQx1UaTaibEukndQrCPLVMcRt1LVFpVSq3YrdRjENBtMkG Copy","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"why-use-interfaces","dir":"Articles","previous_headings":"","what":"Why Use Interfaces?","title":"Introduction to interface","text":"Interfaces R can beneficial several reasons: Code Structure: provide clear contract properties methods object . Type Safety: allow runtime type checking, catching errors early. Documentation: serve self-documenting code, clearly stating expected structure objects. Flexibility: allow implementation multiple interfaces, promoting code reuse. interface package provides following: Interfaces: Define implement interfaces type checking. Interfaces can extended nested. Typed Functions: Define functions strict type constraints. Typed Data Frames: Create data frames column type constraints row validation. Data frames can custom validation functions row callbacks. Enums: Define use enumerated types stricter type safety.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"installation","dir":"Articles","previous_headings":"","what":"Installation","title":"Introduction to interface","text":"install package, use following command:","code":"# Install the package from the source remotes::install_github(\"dereckmezquita/interface\")"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"usage","dir":"Articles","previous_headings":"","what":"Usage","title":"Introduction to interface","text":"Import package functions.","code":"box::use(interface[interface, type.frame, fun, enum])"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"interfaces","dir":"Articles","previous_headings":"Usage","what":"Interfaces","title":"Introduction to interface","text":"define interface, use interface() function:","code":"# Define an interface Person <- interface( name = character, age = numeric, email = character ) # Implement the interface john <- Person( name = \"John Doe\", age = 30, email = \"john@example.com\" ) print(john) #> Object implementing interface: #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled # interfaces are lists print(john$name) #> [1] \"John Doe\" # Valid assignment john$age <- 10 print(john$age) #> [1] 10 # Invalid assignment (throws error) try(john$age <- \"thirty\") #> Error : Property 'age' must be of type numeric"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"nested-interfaces-and-extending-interfaces","dir":"Articles","previous_headings":"Usage","what":"Nested Interfaces and Extending Interfaces","title":"Introduction to interface","text":"can create nested interfaces extend existing interfaces:","code":"# Define an Address interface Address <- interface( street = character, city = character, postal_code = character ) # Define a Scholarship interface Scholarship <- interface( amount = numeric, status = logical ) # Extend the Person and Address interfaces Student <- interface( extends = c(Address, Person), # will inherit properties from Address and Person student_id = character, scores = data.table::data.table, scholarship = Scholarship # nested interface ) # Implement the extended interface john_student <- Student( name = \"John Doe\", age = 30, email = \"john@example.com\", street = \"123 Main St\", city = \"Small town\", postal_code = \"12345\", student_id = \"123456\", scores = data.table::data.table( subject = c(\"Math\", \"Science\"), score = c(95, 88) ), scholarship = Scholarship( amount = 5000, status = TRUE ) ) print(john_student) #> Object implementing interface: #> student_id: 123456 #> scores: Math #> scores: Science #> scores: 95 #> scores: 88 #> scholarship: #> street: 123 Main St #> city: Small town #> postal_code: 12345 #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"custom-validation-functions","dir":"Articles","previous_headings":"Usage","what":"Custom Validation Functions","title":"Introduction to interface","text":"Interfaces can custom validation functions:","code":"is_valid_email <- function(x) { grepl(\"[a-z|0-9]+\\\\@[a-z|0-9]+\\\\.[a-z|0-9]+\", x) } UserProfile <- interface( username = character, email = is_valid_email, age = function(x) is.numeric(x) && x >= 18 ) # Implement with valid data valid_user <- UserProfile( username = \"john_doe\", email = \"john@example.com\", age = 25 ) print(valid_user) #> Object implementing interface: #> username: john_doe #> email: john@example.com #> age: 25 #> Validation on access: Disabled # Invalid implementation (throws error) try(UserProfile( username = \"jane_doe\", email = \"not_an_email\", age = \"30\" )) #> Error : Errors occurred during interface creation: #> - Invalid value for property 'email': FALSE #> - Invalid value for property 'age': FALSE"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"enums","dir":"Articles","previous_headings":"Usage","what":"Enums","title":"Introduction to interface","text":"Enums provide way define set named constants. useful representing fixed set values can used interfaces ensure property takes one predefined set values.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"creating-and-using-enums","dir":"Articles","previous_headings":"Usage > Enums","what":"Creating and Using Enums","title":"Introduction to interface","text":"","code":"# Define an enum for days of the week DaysOfWeek <- enum(\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\") # Create an enum object today <- DaysOfWeek(\"Wednesday\") print(today) #> Enum: Wednesday # Valid assignment today$value <- \"Friday\" print(today) #> Enum: Friday # Invalid assignment (throws error) try(today$value <- \"NotADay\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"NotADay\") : #> Invalid value. Must be one of: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"using-enums-in-interfaces","dir":"Articles","previous_headings":"Usage > Enums","what":"Using Enums in Interfaces","title":"Introduction to interface","text":"Enums can used property types interfaces:","code":"# Define an interface using an enum Meeting <- interface( title = character, day = DaysOfWeek, start_time = numeric, duration = numeric ) # Create a valid meeting object standup <- Meeting( title = \"Daily Standup\", day = \"Monday\", start_time = 9.5, # 9:30 AM duration = 0.5 # 30 minutes ) print(standup) #> Object implementing interface: #> title: Daily Standup #> day: Monday #> start_time: 9.5 #> duration: 0.5 #> Validation on access: Disabled # Invalid day (throws error) try(Meeting( title = \"Invalid Meeting\", day = \"InvalidDay\", start_time = 10, duration = 1 )) #> Error : Errors occurred during interface creation: #> - Invalid enum value for property 'day': Invalid value. Must be one of: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"in-place-enum-declaration-in-interfaces","dir":"Articles","previous_headings":"Usage > Enums","what":"In-place Enum Declaration in Interfaces","title":"Introduction to interface","text":"can also declare enums directly within interface definition: Enums provide additional layer type safety clarity code. ensure certain properties can take predefined set values, reducing chance errors making code self-documenting.","code":"# Define an interface with an in-place enum Task <- interface( description = character, priority = enum(\"Low\", \"Medium\", \"High\"), status = enum(\"Todo\", \"InProgress\", \"Done\") ) # Create a task object my_task <- Task( description = \"Complete project report\", priority = \"High\", status = \"InProgress\" ) print(my_task) #> Object implementing interface: #> description: Complete project report #> priority: High #> status: InProgress #> Validation on access: Disabled # Update task status my_task$status$value <- \"Done\" print(my_task) #> Object implementing interface: #> description: Complete project report #> priority: High #> status: Done #> Validation on access: Disabled # Invalid priority (throws error) try(my_task$priority$value <- \"VeryHigh\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"VeryHigh\") : #> Invalid value. Must be one of: Low, Medium, High"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"typed-functions","dir":"Articles","previous_headings":"Usage","what":"Typed Functions","title":"Introduction to interface","text":"Define functions strict type constraints:","code":"typed_fun <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x + y) } ) # Valid call print(typed_fun(1, 2)) # [1] 3 #> [1] 3 # Invalid call (throws error) try(typed_fun(\"a\", 2)) #> Error : Property 'x' must be of type numeric"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"functions-with-multiple-possible-return-types","dir":"Articles","previous_headings":"Usage > Typed Functions","what":"Functions with Multiple Possible Return Types","title":"Introduction to interface","text":"","code":"typed_fun2 <- fun( x = c(numeric, character), y = numeric, return = c(numeric, character), impl = function(x, y) { if (is.numeric(x)) { return(x + y) } else { return(paste(x, y)) } } ) print(typed_fun2(1, 2)) # [1] 3 #> [1] 3 print(typed_fun2(\"a\", 2)) # [1] \"a 2\" #> [1] \"a 2\""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"typed-data-framedata-tables","dir":"Articles","previous_headings":"Usage","what":"Typed data.frame/data.tables","title":"Introduction to interface","text":"Create data frames column type constraints row validation:","code":"PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical ) ) # Create a data frame persons <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 30, 35), is_student = c(TRUE, FALSE, TRUE) ) print(persons) #> Typed Data Frame Summary: #> Base Frame Type: data.frame #> Dimensions: 3 rows x 4 columns #> #> Column Specifications: #> id : integer #> name : character #> age : numeric #> is_student : logical #> #> Frame Properties: #> Freeze columns : Yes #> Allow NA : Yes #> On violation : error #> #> Data Preview: #> id name age is_student #> 1 1 Alice 25 TRUE #> 2 2 Bob 30 FALSE #> 3 3 Charlie 35 TRUE # Invalid modification (throws error) try(persons$id <- letters[1:3]) #> Error : Property 'id' must be of type integer"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"additional-options","dir":"Articles","previous_headings":"Usage > Typed data.frame/data.tables","what":"Additional Options","title":"Introduction to interface","text":"","code":"PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical, gender = enum(\"M\", \"F\"), email = function(x) all(grepl(\"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$\", x)) # functions are applied to whole column ), freeze_n_cols = FALSE, row_callback = function(row) { if (row$age >= 40) { return(sprintf(\"Age must be less than 40 (got %d)\", row$age)) } if (row$name == \"Yanice\") { return(\"Name cannot be 'Yanice'\") } return(TRUE) }, allow_na = FALSE, on_violation = \"error\" ) df <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 35, 35), is_student = c(TRUE, FALSE, TRUE), gender = c(\"F\", \"M\", \"M\"), email = c(\"alice@test.com\", \"bob_no_valid@test.com\", \"charlie@example.com\") ) print(df) #> Typed Data Frame Summary: #> Base Frame Type: data.frame #> Dimensions: 3 rows x 6 columns #> #> Column Specifications: #> id : integer #> name : character #> age : numeric #> is_student : logical #> gender : Enum(M, F) #> email : custom function #> #> Frame Properties: #> Freeze columns : No #> Allow NA : No #> On violation : error #> #> Data Preview: #> id name age is_student gender email #> 1 1 TRUE 1 TRUE TRUE TRUE #> 2 1 TRUE 1 TRUE TRUE TRUE #> 3 1 TRUE 1 TRUE TRUE TRUE summary(df) #> id name age is_student #> Min. :1 Length:3 Min. :1 Mode:logical #> 1st Qu.:1 Class :character 1st Qu.:1 TRUE:3 #> Median :1 Mode :character Median :1 #> Mean :1 Mean :1 #> 3rd Qu.:1 3rd Qu.:1 #> Max. :1 Max. :1 #> gender.Length gender.Class gender.Mode email #> 1 -none- logical Length:3 #> 1 -none- logical Class :character #> 1 -none- logical Mode :character #> #> #> # Invalid row addition (throws error) try(rbind(df, data.frame( id = 4, name = \"David\", age = 500, is_student = TRUE, email = \"d@test.com\" ))) #> Error in rbind(deparse.level, ...) : Number of columns must match"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"conclusion","dir":"Articles","previous_headings":"","what":"Conclusion","title":"Introduction to interface","text":"package provides powerful tools ensuring type safety validation R. defining interfaces, enums, typed functions, typed data frames, can create robust reliable data structures functions strict type constraints. vignette demonstrates basic usage capabilities package. details, refer package documentation examples provided source code.","code":""},{"path":"https://dereckmezquita.github.io/interface/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Dereck Mezquita. Author, maintainer.","code":""},{"path":"https://dereckmezquita.github.io/interface/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Mezquita, D. (2024). interface: Runtime Type System R. R package version 0.1.0. https://github.com/dereckmezquita/interface","code":"@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}, }"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"interface","dir":"","previous_headings":"","what":"Runtime Type System for R","title":"Runtime Type System for R","text":"interface package provides system defining implementing interfaces R, runtime type checking, bringing benefits statically-typed languages R zero dependencies. interface provides: Interfaces: Define implement interfaces type checking. Interfaces can extended nested. Typed Functions: Define functions strict type constraints. Typed Frames: Choose data.frame data.table column type constraints row validation. Enums: Define use enumerated types stricter type safety.","code":""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Runtime Type System for R","text":"install package, use following command:","code":"# Install the package from the source remotes::install_github(\"dereckmezquita/interface\")"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"getting-started","dir":"","previous_headings":"","what":"Getting started","title":"Runtime Type System for R","text":"Import package functions. Define interface implement :","code":"box::use(interface[ interface, type.frame, fun, enum ]) # Define an interface Person <- interface( name = character, age = numeric, email = character ) # Implement the interface john <- Person( name = \"John Doe\", age = 30, email = \"john@example.com\" ) print(john) #> Object implementing interface: #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled # interfaces are lists print(john$name) #> [1] \"John Doe\" # Modify the object john$age <- 10 print(john$age) #> [1] 10 # Invalid assignment (throws error) try(john$age <- \"thirty\") #> Error : Property 'age' must be of type numeric"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"extending-interfaces-and-nested-interfaces","dir":"","previous_headings":"Getting started","what":"Extending Interfaces and Nested Interfaces","title":"Runtime Type System for R","text":"Create nested extended interfaces:","code":"# Define nested interfaces Address <- interface( street = character, city = character, postal_code = character ) Scholarship <- interface( amount = numeric, status = logical ) # Extend interfaces Student <- interface( extends = c(Address, Person), student_id = character, scores = data.table::data.table, scholarship = Scholarship ) # Implement the extended interface john_student <- Student( name = \"John Doe\", age = 30, email = \"john@example.com\", street = \"123 Main St\", city = \"Small town\", postal_code = \"12345\", student_id = \"123456\", scores = data.table::data.table( subject = c(\"Math\", \"Science\"), score = c(95, 88) ), scholarship = Scholarship( amount = 5000, status = TRUE ) ) print(john_student) #> Object implementing interface: #> student_id: 123456 #> scores: Math #> scores: Science #> scores: 95 #> scores: 88 #> scholarship: #> street: 123 Main St #> city: Small town #> postal_code: 12345 #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"custom-validation-functions","dir":"","previous_headings":"Getting started","what":"Custom Validation Functions","title":"Runtime Type System for R","text":"Interfaces can custom validation functions:","code":"is_valid_email <- function(x) { grepl(\"[a-z|0-9]+\\\\@[a-z|0-9]+\\\\.[a-z|0-9]+\", x) } UserProfile <- interface( username = character, email = is_valid_email, age = function(x) is.numeric(x) && x >= 18 ) # Implement with valid data valid_user <- UserProfile( username = \"john_doe\", email = \"john@example.com\", age = 25 ) print(valid_user) #> Object implementing interface: #> username: john_doe #> email: john@example.com #> age: 25 #> Validation on access: Disabled # Invalid implementation (throws error) try(UserProfile( username = \"jane_doe\", email = \"not_an_email\", age = \"30\" )) #> Error : Errors occurred during interface creation: #> - Invalid value for property 'email': FALSE #> - Invalid value for property 'age': FALSE"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"typed-functions","dir":"","previous_headings":"Getting started","what":"Typed Functions","title":"Runtime Type System for R","text":"Define functions strict type constraints: Functions multiple possible return types:","code":"typed_fun <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x + y) } ) print(typed_fun(1, 2)) # [1] 3 #> [1] 3 try(typed_fun(\"a\", 2)) # Invalid call #> Error : Property 'x' must be of type numeric typed_fun2 <- fun( x = c(numeric, character), y = numeric, return = c(numeric, character), impl = function(x, y) { if (is.numeric(x)) { return(x + y) } else { return(paste(x, y)) } } ) print(typed_fun2(1, 2)) # [1] 3 #> [1] 3 print(typed_fun2(\"a\", 2)) # [1] \"a 2\" #> [1] \"a 2\""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"typed-data-frames-and-data-tables","dir":"","previous_headings":"Getting started","what":"Typed Data Frames and Data Tables","title":"Runtime Type System for R","text":"Create data frames column type constraints row validation: Additional options data frame validation:","code":"PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical ) ) # Create a data frame persons <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 30, 35), is_student = c(TRUE, FALSE, TRUE) ) print(persons) #> [1mTyped Data Frame Summary:[0m #> Base Frame Type: data.frame #> Dimensions: 3 rows x 4 columns #> #> [1mColumn Specifications:[0m #> id : integer #> name : character #> age : numeric #> is_student : logical #> #> [1mFrame Properties:[0m #> Freeze columns : Yes #> Allow NA : Yes #> On violation : error #> #> [1mData Preview:[0m #> id name age is_student #> 1 1 Alice 25 TRUE #> 2 2 Bob 30 FALSE #> 3 3 Charlie 35 TRUE # Invalid modification (throws error) try(persons$id <- letters[1:3]) #> Error in `$<-.typed_frame`(`*tmp*`, id, value = c(\"a\", \"b\", \"c\")) : #> object 'col_name' not found PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical, gender = enum(\"M\", \"F\"), email = function(x) all(grepl(\"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$\", x)) ), freeze_n_cols = FALSE, row_callback = function(row) { if (row$age >= 40) { return(sprintf(\"Age must be less than 40 (got %d)\", row$age)) } if (row$name == \"Yanice\") { return(\"Name cannot be 'Yanice'\") } return(TRUE) }, allow_na = FALSE, on_violation = \"error\" ) df <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 35, 35), is_student = c(TRUE, FALSE, TRUE), gender = c(\"F\", \"M\", \"M\"), email = c(\"alice@test.com\", \"bob_no_valid@test.com\", \"charlie@example.com\") ) print(df) #> [1mTyped Data Frame Summary:[0m #> Base Frame Type: data.frame #> Dimensions: 3 rows x 6 columns #> #> [1mColumn Specifications:[0m #> id : integer #> name : character #> age : numeric #> is_student : logical #> gender : Enum(M, F) #> email : custom function #> #> [1mFrame Properties:[0m #> Freeze columns : No #> Allow NA : No #> On violation : error #> #> [1mData Preview:[0m #> id name age is_student gender email #> 1 1 TRUE 1 TRUE TRUE TRUE #> 2 1 TRUE 1 TRUE TRUE TRUE #> 3 1 TRUE 1 TRUE TRUE TRUE summary(df) #> id name age is_student #> Min. :1 Length:3 Min. :1 Mode:logical #> 1st Qu.:1 Class :character 1st Qu.:1 TRUE:3 #> Median :1 Mode :character Median :1 #> Mean :1 Mean :1 #> 3rd Qu.:1 3rd Qu.:1 #> Max. :1 Max. :1 #> gender.Length gender.Class gender.Mode email #> 1 -none- logical Length:3 #> 1 -none- logical Class :character #> 1 -none- logical Mode :character #> #> #> # Invalid row addition (throws error) try(rbind(df, data.frame( id = 4, name = \"David\", age = 50, is_student = TRUE, email = \"d@test.com\" ))) #> Error in rbind(deparse.level, ...) : Number of columns must match"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"enums","dir":"","previous_headings":"Getting started","what":"Enums","title":"Runtime Type System for R","text":"Define enums categorical variables; safe use protect value modified invalid options. enum function creates generator used create enum object. can used standalone part interface.","code":"Colour <- enum(\"red\", \"green\", \"blue\") # Create an enum object colour <- Colour(\"red\") print(colour) #> Enum: red colour$value <- \"green\" print(colour) #> Enum: green # Invalid modification (throws error) try(colour$value <- \"yellow\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue # Use in an interface Car <- interface( make = enum(\"Toyota\", \"Ford\", \"Chevrolet\"), model = character, colour = Colour ) # Implement the interface car1 <- Car( make = \"Toyota\", model = \"Corolla\", colour = \"red\" ) print(car1) #> Object implementing interface: #> make: Toyota #> model: Corolla #> colour: red #> Validation on access: Disabled # Invalid implementation (throws error) try(Car( make = \"Honda\", model = \"Civic\", colour = \"yellow\" )) #> Error : Errors occurred during interface creation: #> - Invalid enum value for property 'make': Invalid value. Must be one of: Toyota, Ford, Chevrolet #> - Invalid enum value for property 'colour': Invalid value. Must be one of: red, green, blue # Invalid modification (throws error) try(car1$colour$value <- \"yellow\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue try(car1$make$value <- \"Honda\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"Honda\") : #> Invalid value. Must be one of: Toyota, Ford, Chevrolet"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"conclusion","dir":"","previous_headings":"","what":"Conclusion","title":"Runtime Type System for R","text":"interface package provides powerful tools ensuring type safety validation R. defining interfaces, typed functions, typed data frames, can create robust reliable data structures functions strict type constraints. details, refer package documentation.","code":""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"license","dir":"","previous_headings":"","what":"License","title":"Runtime Type System for R","text":"package licensed MIT License.","code":""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Runtime Type System for R","text":"use package research work, please cite : Mezquita, D. (2024). interface: Runtime Type System R. R package version 0.1.0. https://github.com/dereckmezquita/interface","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Get value from enum object — $.enum","title":"Get value from enum object — $.enum","text":"Retrieves value enum object.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get value from enum object — $.enum","text":"","code":"# S3 method for class 'enum' x$name"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get value from enum object — $.enum","text":"x enum object name name field access (\"value\")","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get value from enum object — $.enum","text":"value enum object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get value from enum object — $.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") my_color <- Colors(\"red\") my_color$value # \"red\" #> [1] \"red\""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.interface_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Get a property from an interface object — $.interface_object","title":"Get a property from an interface object — $.interface_object","text":"Get property interface object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.interface_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get a property from an interface object — $.interface_object","text":"","code":"# S3 method for class 'interface_object' x$name"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.interface_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get a property from an interface object — $.interface_object","text":"x interface object name name property get","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Set value of enum object — $<-.enum","title":"Set value of enum object — $<-.enum","text":"Sets value enum object. new value must one valid enum values.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Set value of enum object — $<-.enum","text":"","code":"# S3 method for class 'enum' x$name <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Set value of enum object — $<-.enum","text":"x enum object name name field set (\"value\") value new value set","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Set value of enum object — $<-.enum","text":"updated enum object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Set value of enum object — $<-.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") my_color <- Colors(\"red\") my_color$value <- \"blue\" # Valid assignment try(my_color$value <- \"yellow\") # This will raise an error #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.interface_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Set a property in an interface object — $<-.interface_object","title":"Set a property in an interface object — $<-.interface_object","text":"Set property interface object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.interface_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Set a property in an interface object — $<-.interface_object","text":"","code":"# S3 method for class 'interface_object' x$name <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.interface_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Set a property in an interface object — $<-.interface_object","text":"x interface object name name property set value new value property","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify a typed data frame using $ — $<-.typed_frame","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"Allows modifying typed data frame using $ operator, validation checks.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"","code":"# S3 method for class 'typed_frame' x$col_name <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"x typed data frame. col_name name column modify add. value new value assign.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"modified typed data frame.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an enumerated type — enum","title":"Create an enumerated type — enum","text":"Creates enumerated type fixed set possible values. function returns enum generator, can used create enum objects values restricted specified set.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an enumerated type — enum","text":"","code":"enum(...)"},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an enumerated type — enum","text":"... possible values enumerated type. unique character strings.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an enumerated type — enum","text":"function (enum generator) creates enum objects defined type.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create an enumerated type — enum","text":"","code":"# Create an enum type for colors Colors <- enum(\"red\", \"green\", \"blue\") # Create enum objects my_color <- Colors(\"red\") print(my_color) # Output: Enum: red #> Enum: red # Trying to create an enum with an invalid value will raise an error try(Colors(\"yellow\")) #> Error in Colors(\"yellow\") : #> Invalid value. Must be one of: red, green, blue # Enums can be used in interfaces ColoredShape <- interface( shape = character, color = Colors ) my_shape <- ColoredShape(shape = \"circle\", color = \"red\") # Modifying enum values my_shape$color$value <- \"blue\" # This is valid try(my_shape$color$value <- \"yellow\") # This will raise an error #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue"},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality comparison for enum objects — ==.enum","title":"Equality comparison for enum objects — ==.enum","text":"Compares two enum objects enum object character value.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality comparison for enum objects — ==.enum","text":"","code":"# S3 method for class 'enum' e1 == e2"},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Equality comparison for enum objects — ==.enum","text":"e1 First enum object e2 Second enum object character value","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Equality comparison for enum objects — ==.enum","text":"Logical value indicating whether two objects equal","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality comparison for enum objects — ==.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") color1 <- Colors(\"red\") color2 <- Colors(\"blue\") color1 == color2 # FALSE #> [1] FALSE color1 == Colors(\"red\") # TRUE #> [1] TRUE color1 == \"red\" # TRUE #> [1] TRUE"},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a typed function — fun","title":"Create a typed function — fun","text":"Defines function specified parameter types return type. Ensures function's arguments return value adhere specified types.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a typed function — fun","text":"","code":"fun(...)"},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a typed function — fun","text":"... Named arguments defining function parameters types, including 'return' expected return type(s) 'impl' function implementation.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a typed function — fun","text":"typed function enforces type constraints parameters return value.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a typed function — fun","text":"`fun` function allows define function strict type checking parameters return value. ensures function receives arguments correct types returns value expected type. 'return' 'impl' arguments included ... parameter list.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a typed function — fun","text":"","code":"# Define a typed function that adds two numbers add_numbers <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x + y) } ) # Valid call print(add_numbers(1, 2)) # [1] 3 #> [1] 3 # Invalid call (throws error) try(add_numbers(\"a\", 2)) #> Error : Property 'x' must be of type numeric # Define a typed function with multiple return types concat_or_add <- fun( x = c(numeric, character), y = numeric, return = c(numeric, character), impl = function(x, y) { if (is.numeric(x)) { return(x + y) } else { return(paste(x, y)) } } ) # Valid calls print(concat_or_add(1, 2)) # [1] 3 #> [1] 3 print(concat_or_add(\"a\", 2)) # [1] \"a 2\" #> [1] \"a 2\""},{"path":"https://dereckmezquita.github.io/interface/reference/handle_violation.html","id":null,"dir":"Reference","previous_headings":"","what":"Handle violations based on the specified action — handle_violation","title":"Handle violations based on the specified action — handle_violation","text":"Handles violations either throwing error, issuing warning, nothing, depending specified action.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/handle_violation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Handle violations based on the specified action — handle_violation","text":"","code":"handle_violation(message, action)"},{"path":"https://dereckmezquita.github.io/interface/reference/handle_violation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Handle violations based on the specified action — handle_violation","text":"message error message handled. action action take: \"error\", \"warning\", \"silent\".","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":null,"dir":"Reference","previous_headings":"","what":"Define an interface — interface","title":"Define an interface — interface","text":"interface defines structure specified properties types validation functions. useful ensuring objects adhere particular format type constraints.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Define an interface — interface","text":"","code":"interface(..., validate_on_access = FALSE, extends = list())"},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Define an interface — interface","text":"... Named arguments defining properties types validation functions. validate_on_access Logical, whether validate properties access (default: FALSE). extends list interfaces interface extends.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Define an interface — interface","text":"function create objects implement defined interface.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Define an interface — interface","text":"","code":"# Define an interface for a person Person <- interface( name = character, age = numeric, email = character ) # Create an object that implements the Person interface john <- Person( name = \"John Doe\", age = 30, email = \"john@example.com\" ) # Using enum in an interface Colors <- enum(\"red\", \"green\", \"blue\") ColoredShape <- interface( shape = character, color = Colors ) my_shape <- ColoredShape(shape = \"circle\", color = \"red\") # In-place enum declaration Car <- interface( make = character, model = character, color = enum(\"red\", \"green\", \"blue\") ) my_car <- Car(make = \"Toyota\", model = \"Corolla\", color = \"red\")"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for enum objects — print.enum","title":"Print method for enum objects — print.enum","text":"Prints human-readable representation enum object.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for enum objects — print.enum","text":"","code":"# S3 method for class 'enum' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for enum objects — print.enum","text":"x enum object ... Additional arguments (used)","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for enum objects — print.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") my_color <- Colors(\"red\") print(my_color) # Output: Enum: red #> Enum: red"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for enum generators — print.enum_generator","title":"Print method for enum generators — print.enum_generator","text":"Prints human-readable representation enum generator, showing possible values.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for enum generators — print.enum_generator","text":"","code":"# S3 method for class 'enum_generator' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for enum generators — print.enum_generator","text":"x enum generator function ... Additional arguments (used)","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for enum generators — print.enum_generator","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") print(Colors) # Output: Enum generator: red, green, blue #> Enum generator: red, green, blue"},{"path":"https://dereckmezquita.github.io/interface/reference/print.interface_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for interface objects — print.interface_object","title":"Print method for interface objects — print.interface_object","text":"Print method interface objects","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.interface_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for interface objects — print.interface_object","text":"","code":"# S3 method for class 'interface_object' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.interface_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for interface objects — print.interface_object","text":"x object implementing interface ... Additional arguments (used)","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for typed data frames — print.typed_frame","title":"Print method for typed data frames — print.typed_frame","text":"Provides custom print method typed data frames, displaying properties validation status.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for typed data frames — print.typed_frame","text":"","code":"# S3 method for class 'typed_frame' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for typed data frames — print.typed_frame","text":"x typed data frame. ... Additional arguments passed print.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for typed functions — print.typed_function","title":"Print method for typed functions — print.typed_function","text":"Provides custom print method typed functions, displaying parameter types return type.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for typed functions — print.typed_function","text":"","code":"# S3 method for class 'typed_function' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for typed functions — print.typed_function","text":"x typed function. ... Additional arguments (used).","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for typed functions — print.typed_function","text":"","code":"# Define a typed function multiply <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x * y) } ) # Print the typed function print(multiply) #> Typed function: #> Arguments: #> x: function (length = 0L) #> x: .Internal(vector(\"double\", length)) #> y: function (length = 0L) #> y: .Internal(vector(\"double\", length)) #> Return type: function (length = 0L) #> Return type: .Internal(vector(\"double\", length))"},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Combine typed data frames row-wise — rbind.typed_frame","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"function combines multiple typed data frames row-wise, ensuring type consistency applying row validation rules. extends base rbind function adding type checks row validation based specified rules typed data frames.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"","code":"# S3 method for class 'typed_frame' rbind(..., deparse.level = 1)"},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"... Typed data frames combine. deparse.level See rbind.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"combined typed data frame.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"version rbind typed_frame performs extra type checking row validation ensure consistency adherence specified rules. Refer base rbind documentation additional details combining data frames: rbind.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify a typed data frame using [ ] — [<-.typed_frame","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"Allows modifying typed data frame using [ ] operator, validation checks.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"","code":"# S3 method for class 'typed_frame' x[i, j] <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"x typed data frame. Row index. j Column index name. value new value assign.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"modified typed data frame.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a typed data frame — type.frame","title":"Create a typed data frame — type.frame","text":"Creates data frame specified column types validation rules. Ensures data frame adheres specified structure validation rules creation modification.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a typed data frame — type.frame","text":"","code":"type.frame( frame, col_types, freeze_n_cols = TRUE, row_callback = NULL, allow_na = TRUE, on_violation = c(\"error\", \"warning\", \"silent\") )"},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a typed data frame — type.frame","text":"frame base data structure (e.g., data.frame, data.table). col_types list column types validators. freeze_n_cols Logical, whether freeze number columns (default: TRUE). row_callback function validate process row (optional). allow_na Logical, whether allow NA values (default: TRUE). on_violation Action take violation: \"error\", \"warning\", \"silent\" (default: \"error\").","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a typed data frame — type.frame","text":"function creates typed data frames.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a typed data frame — type.frame","text":"`type.frame` function defines blueprint data frame, specifying types columns optional validation rules rows. data frame created modified using blueprint, ensures data adheres specified rules.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a typed data frame — type.frame","text":"","code":"# Define a typed data frame PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical ) ) # Create a data frame persons <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 30, 35), is_student = c(TRUE, FALSE, TRUE) ) print(persons) #> Typed Data Frame Summary: #> Base Frame Type: data.frame #> Dimensions: 3 rows x 4 columns #> #> Column Specifications: #> id : integer #> name : character #> age : numeric #> is_student : logical #> #> Frame Properties: #> Freeze columns : Yes #> Allow NA : Yes #> On violation : error #> #> Data Preview: #> id name age is_student #> 1 1 Alice 25 TRUE #> 2 2 Bob 30 FALSE #> 3 3 Charlie 35 TRUE # Invalid modification (throws error) try(persons$id <- letters[1:3]) #> Error : Property 'id' must be of type integer # Adding a column (throws error if freeze_n_cols is TRUE) try(persons$yeet <- letters[1:3]) #> Error in `$<-.typed_frame`(`*tmp*`, yeet, value = c(\"a\", \"b\", \"c\")) : #> Adding new columns is not allowed when freeze_n_cols is TRUE"},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate a property against a given type or validation function — validate_property","title":"Validate a property against a given type or validation function — validate_property","text":"Validates property ensure matches expected type satisfies given validation function.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate a property against a given type or validation function — validate_property","text":"","code":"validate_property(name, value, validator)"},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate a property against a given type or validation function — validate_property","text":"name name property validated. value value property. validator expected type custom validation function.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate a property against a given type or validation function — validate_property","text":"NULL validation passes, otherwise error message.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"Modifies user-defined function wrap body () call, ensuring returns single logical value instead vector. uses bquote() create new body function. .() inside bquote() inserts original body function. () function wraps around original body.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"","code":"wrap_fun_in_all(user_fun)"},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"user_fun user-defined function.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"modified function.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"breaking-changes-0-1-0","dir":"Changelog","previous_headings":"","what":"BREAKING CHANGES","title":"interface v0.1.0 (in development)","text":"N/","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"new-features-0-1-0","dir":"Changelog","previous_headings":"","what":"NEW FEATURES","title":"interface v0.1.0 (in development)","text":"Implemented core functionality defining implementing interfaces. Added support optional runtime type checking. Included support nested interfaces custom validation functions. Created comprehensive documentation vignettes. Implemented enum functionality defining enumerated types. Added typed functions strict type constraints. Implemented typed data frames data tables column type constraints row validation.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"improvements-0-1-0","dir":"Changelog","previous_headings":"","what":"IMPROVEMENTS","title":"interface v0.1.0 (in development)","text":"Enhanced package structure organization. Improved error handling informative error messages. Optimized performance type checking operations.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"documentation-0-1-0","dir":"Changelog","previous_headings":"","what":"DOCUMENTATION","title":"interface v0.1.0 (in development)","text":"Created detailed vignettes package usage examples. Improved function documentation examples clearer explanations. Added README installation instructions quick start guide.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"development-0-1-0","dir":"Changelog","previous_headings":"","what":"DEVELOPMENT","title":"interface v0.1.0 (in development)","text":"Set continuous integration GitHub Actions. Implemented comprehensive test suite using testthat. Ensured CRAN policy compliance.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"notes-0-1-0","dir":"Changelog","previous_headings":"","what":"NOTES","title":"interface v0.1.0 (in development)","text":"first release interface package. package compatible R versions 4.1.0 .","code":""}] +[{"path":[]},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description","dir":"","previous_headings":"1. Support for typed functions","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow defining functions typed arguments return values. require mechanism extending base R types.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas","dir":"","previous_headings":"1. Support for typed functions","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"","code":"function2 <- interface(\"function\", arg1 = \"numeric\", arg2 = \"character\", return = \"numeric\" ) # Implement the function f2 <- implement(function2, function(arg1, arg2) { return(arg1 + nchar(arg2)) })"},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-1","dir":"","previous_headings":"2. Support for generics with runtime enforcement","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow defining generic interface, allow one enforce types across data.frame columns example.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-1","dir":"","previous_headings":"2. Support for generics with runtime enforcement","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"","code":"# Define a interface with n character columns and m numeric columns Df <- interface(\"data.frame\", name = \"character\", height = \"numeric\", age = \"numeric\" ) # Implement the interface df1 <- implement(Df, data.frame( name = c(\"John\", \"Jane\"), height = c(5.8, 6.0), age = c(30, 25) ) ) # This should raise an error df1$age <- c(\"30\", \"25\")"},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-2","dir":"","previous_headings":"3. Allow for generics with either or types","what":"Description","title":"interface v0.1.0 (in development)","text":"Much way TypeScript allows Union Types, can allow Union Types interface package.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-2","dir":"","previous_headings":"3. Allow for generics with either or types","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"","code":"CharNumList <- interface(\"list\", value = c(\"character\", \"numeric\") ) # Implement the interface list1 <- implement(CharNumList, list(\"John\", 30)) Df <- interface(\"data.frame\", name = \"character\", height = c(\"numeric\", \"character\"), age = \"numeric\" )"},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-3","dir":"","previous_headings":"4. Implement Atomic Types","what":"Description","title":"interface v0.1.0 (in development)","text":"Create new way define atomic types, similar TypeScript’s type aliases. allow users define types single values instead lists .e. difference type interface TypeScript. way user even flexibility check length atomic type.","code":"type Cohort = \"alpha\" | \"beta\" | \"gamma\"; interface Person { name: string; age: number; cohort: Cohort; }"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-3","dir":"","previous_headings":"4. Implement Atomic Types","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"Create new function, type(), defines atomic types; instead returning list return vectors (since atomic types vectors R). Modify check_type() function handle new atomic types. Update implement() function return atomic values appropriate.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"example-usage","dir":"","previous_headings":"4. Implement Atomic Types","what":"Example Usage","title":"interface v0.1.0 (in development)","text":"","code":"Cohort <- type(\"Cohort\", c(\"alpha\", \"beta\", \"gamma\")) # by default the validate function only checks for membership cohort1 <- implement(Cohort, \"alpha\") # custom function for type checking Age <- type(\"Age\", function(x) { return(is.numeric(x) && x >= 0 && x <= 120 && length(x) == 1) }) # Use the atomic type john_age <- implement(Age, 30) print(john_age) # Should print a vector of length 1 # This should raise an error try(implement(Age, 150))"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"integration-with-existing-codebase","dir":"","previous_headings":"4. Implement Atomic Types","what":"Integration with Existing Codebase","title":"interface v0.1.0 (in development)","text":"Add new file R/type.R contain type() function related helpers. Modify R/implement.R handle atomic types differently interfaces. Update R/helpers.R include type checking atomic types. Add new print functions R/print.R handle atomic types.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-4","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow interfaces extend interfaces existing R types, similar inheritance object-oriented programming.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-4","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"Modify interface() function accept extends parameter. Update check_interface() function check properties extended interfaces types. Implement mechanism resolve property conflicts case multiple extensions.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"example-usage-1","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Example Usage","title":"interface v0.1.0 (in development)","text":"","code":"# Extend an existing interface Person <- interface(\"Person\", name = \"character\", age = \"numeric\" ) Employee <- interface(\"Employee\", extends = Person, job_title = \"character\", salary = \"numeric\" ) john <- implement(Employee, name = \"John Doe\", age = 30, job_title = \"Developer\", salary = 75000 ) # TODO: this needs more work # Extend an existing R type EnhancedDataFrame <- interface(\"EnhancedDataFrame\", extends = \"data.frame\", metadata = \"list\" ) my_df <- implement(EnhancedDataFrame, data.frame(x = 1:3, y = c(\"a\", \"b\", \"c\")), metadata = list(created_at = Sys.time()) )"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"integration-with-existing-codebase-1","dir":"","previous_headings":"5. Extend Interfaces and Existing R Types","what":"Integration with Existing Codebase","title":"interface v0.1.0 (in development)","text":"Modify R/interface.R handle extends parameter. Update R/helpers.R include extended property checking check_interface(). Add new test cases tests/testthat/test-interface.R extension functionality.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"description-5","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Description","title":"interface v0.1.0 (in development)","text":"Allow interfaces specify method signatures, just properties.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"implementation-ideas-5","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Implementation Ideas","title":"interface v0.1.0 (in development)","text":"Extend interface() function accept method signatures. Implement mechanism check object implements required methods.","code":""},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"example-usage-2","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Example Usage","title":"interface v0.1.0 (in development)","text":"","code":"Drawable <- interface(\"Drawable\", methods = list( draw = function() NULL ) ) Circle <- interface(\"Circle\", extends = Drawable, radius = \"numeric\", methods = list( area = function() NULL ) ) my_circle <- implement(Circle, radius = 5, draw = function() { return(cat(\"Drawing a circle\\n\")) }, area = function() { return(pi * self$radius ^ 2) } ) my_circle$draw() print(my_circle$area())"},{"path":"https://dereckmezquita.github.io/interface/TODO.html","id":"integration-with-existing-codebase-2","dir":"","previous_headings":"6. Add Method Signatures to Interfaces","what":"Integration with Existing Codebase","title":"interface v0.1.0 (in development)","text":"Modify R/interface.R handle method signatures. Update R/implement.R check implement methods. Add new test cases tests/testthat/test-interface.R method functionality.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/donate.html","id":"support-my-work","dir":"Articles","previous_headings":"","what":"Support my work","title":"Donate","text":"find package useful, please consider supporting work cryptocurrency donation.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/donate.html","id":"bitcoin","dir":"Articles","previous_headings":"Support my work","what":"Bitcoin","title":"Donate","text":"bc1qgs4f6hhnzj8m2j05axgsf53k67kugps92qzr2k Copy","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/donate.html","id":"monero","dir":"Articles","previous_headings":"Support my work","what":"Monero","title":"Donate","text":"41wSUfpnhVUW5GnTKCyBBwVuokhkjMeepAVkKT1qv3HDhcZhTSQx1UaTaibEukndQrCPLVMcRt1LVFpVSq3YrdRjENBtMkG Copy","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"why-use-interfaces","dir":"Articles","previous_headings":"","what":"Why Use Interfaces?","title":"Introduction to interface","text":"Interfaces R can beneficial several reasons: Code Structure: provide clear contract properties methods object . Type Safety: allow runtime type checking, catching errors early. Documentation: serve self-documenting code, clearly stating expected structure objects. Flexibility: allow implementation multiple interfaces, promoting code reuse. interface package provides following: Interfaces: Define implement interfaces type checking. Interfaces can extended nested. Typed Functions: Define functions strict type constraints. Typed Data Frames: Create data frames column type constraints row validation. Data frames can custom validation functions row callbacks. Enums: Define use enumerated types stricter type safety.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"installation","dir":"Articles","previous_headings":"","what":"Installation","title":"Introduction to interface","text":"install package, use following command:","code":"# Install the package from the source remotes::install_github(\"dereckmezquita/interface\")"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"usage","dir":"Articles","previous_headings":"","what":"Usage","title":"Introduction to interface","text":"Import package functions.","code":"box::use(interface[interface, type.frame, fun, enum])"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"interfaces","dir":"Articles","previous_headings":"Usage","what":"Interfaces","title":"Introduction to interface","text":"define interface, use interface() function:","code":"# Define an interface Person <- interface( name = character, age = numeric, email = character ) # Implement the interface john <- Person( name = \"John Doe\", age = 30, email = \"john@example.com\" ) print(john) #> Object implementing interface: #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled # interfaces are lists print(john$name) #> [1] \"John Doe\" # Valid assignment john$age <- 10 print(john$age) #> [1] 10 # Invalid assignment (throws error) try(john$age <- \"thirty\") #> Error : Property 'age' must be of type numeric"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"nested-interfaces-and-extending-interfaces","dir":"Articles","previous_headings":"Usage","what":"Nested Interfaces and Extending Interfaces","title":"Introduction to interface","text":"can create nested interfaces extend existing interfaces:","code":"# Define an Address interface Address <- interface( street = character, city = character, postal_code = character ) # Define a Scholarship interface Scholarship <- interface( amount = numeric, status = logical ) # Extend the Person and Address interfaces Student <- interface( extends = c(Address, Person), # will inherit properties from Address and Person student_id = character, scores = data.table::data.table, scholarship = Scholarship # nested interface ) # Implement the extended interface john_student <- Student( name = \"John Doe\", age = 30, email = \"john@example.com\", street = \"123 Main St\", city = \"Small town\", postal_code = \"12345\", student_id = \"123456\", scores = data.table::data.table( subject = c(\"Math\", \"Science\"), score = c(95, 88) ), scholarship = Scholarship( amount = 5000, status = TRUE ) ) print(john_student) #> Object implementing interface: #> student_id: 123456 #> scores: Math #> scores: Science #> scores: 95 #> scores: 88 #> scholarship: #> street: 123 Main St #> city: Small town #> postal_code: 12345 #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"custom-validation-functions","dir":"Articles","previous_headings":"Usage","what":"Custom Validation Functions","title":"Introduction to interface","text":"Interfaces can custom validation functions:","code":"is_valid_email <- function(x) { grepl(\"[a-z|0-9]+\\\\@[a-z|0-9]+\\\\.[a-z|0-9]+\", x) } UserProfile <- interface( username = character, email = is_valid_email, age = function(x) is.numeric(x) && x >= 18 ) # Implement with valid data valid_user <- UserProfile( username = \"john_doe\", email = \"john@example.com\", age = 25 ) print(valid_user) #> Object implementing interface: #> username: john_doe #> email: john@example.com #> age: 25 #> Validation on access: Disabled # Invalid implementation (throws error) try(UserProfile( username = \"jane_doe\", email = \"not_an_email\", age = \"30\" )) #> Error : Errors occurred during interface creation: #> - Invalid value for property 'email': FALSE #> - Invalid value for property 'age': FALSE"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"enums","dir":"Articles","previous_headings":"Usage","what":"Enums","title":"Introduction to interface","text":"Enums provide way define set named constants. useful representing fixed set values can used interfaces ensure property takes one predefined set values.","code":""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"creating-and-using-enums","dir":"Articles","previous_headings":"Usage > Enums","what":"Creating and Using Enums","title":"Introduction to interface","text":"","code":"# Define an enum for days of the week DaysOfWeek <- enum(\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\") # Create an enum object today <- DaysOfWeek(\"Wednesday\") print(today) #> Enum: Wednesday # Valid assignment today$value <- \"Friday\" print(today) #> Enum: Friday # Invalid assignment (throws error) try(today$value <- \"NotADay\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"NotADay\") : #> Invalid value. Must be one of: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"using-enums-in-interfaces","dir":"Articles","previous_headings":"Usage > Enums","what":"Using Enums in Interfaces","title":"Introduction to interface","text":"Enums can used property types interfaces:","code":"# Define an interface using an enum Meeting <- interface( title = character, day = DaysOfWeek, start_time = numeric, duration = numeric ) # Create a valid meeting object standup <- Meeting( title = \"Daily Standup\", day = \"Monday\", start_time = 9.5, # 9:30 AM duration = 0.5 # 30 minutes ) print(standup) #> Object implementing interface: #> title: Daily Standup #> day: Monday #> start_time: 9.5 #> duration: 0.5 #> Validation on access: Disabled # Invalid day (throws error) try(Meeting( title = \"Invalid Meeting\", day = \"InvalidDay\", start_time = 10, duration = 1 )) #> Error : Errors occurred during interface creation: #> - Invalid enum value for property 'day': Invalid value. Must be one of: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"in-place-enum-declaration-in-interfaces","dir":"Articles","previous_headings":"Usage > Enums","what":"In-place Enum Declaration in Interfaces","title":"Introduction to interface","text":"can also declare enums directly within interface definition: Enums provide additional layer type safety clarity code. ensure certain properties can take predefined set values, reducing chance errors making code self-documenting.","code":"# Define an interface with an in-place enum Task <- interface( description = character, priority = enum(\"Low\", \"Medium\", \"High\"), status = enum(\"Todo\", \"InProgress\", \"Done\") ) # Create a task object my_task <- Task( description = \"Complete project report\", priority = \"High\", status = \"InProgress\" ) print(my_task) #> Object implementing interface: #> description: Complete project report #> priority: High #> status: InProgress #> Validation on access: Disabled # Update task status my_task$status$value <- \"Done\" print(my_task) #> Object implementing interface: #> description: Complete project report #> priority: High #> status: Done #> Validation on access: Disabled # Invalid priority (throws error) try(my_task$priority$value <- \"VeryHigh\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"VeryHigh\") : #> Invalid value. Must be one of: Low, Medium, High"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"typed-functions","dir":"Articles","previous_headings":"Usage","what":"Typed Functions","title":"Introduction to interface","text":"Define functions strict type constraints:","code":"typed_fun <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x + y) } ) # Valid call print(typed_fun(1, 2)) # [1] 3 #> [1] 3 # Invalid call (throws error) try(typed_fun(\"a\", 2)) #> Error : Property 'x' must be of type numeric"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"functions-with-multiple-possible-return-types","dir":"Articles","previous_headings":"Usage > Typed Functions","what":"Functions with Multiple Possible Return Types","title":"Introduction to interface","text":"","code":"typed_fun2 <- fun( x = c(numeric, character), y = numeric, return = c(numeric, character), impl = function(x, y) { if (is.numeric(x)) { return(x + y) } else { return(paste(x, y)) } } ) print(typed_fun2(1, 2)) # [1] 3 #> [1] 3 print(typed_fun2(\"a\", 2)) # [1] \"a 2\" #> [1] \"a 2\""},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"typed-data-framedata-tables","dir":"Articles","previous_headings":"Usage","what":"Typed data.frame/data.tables","title":"Introduction to interface","text":"Create data frames column type constraints row validation:","code":"PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical ) ) # Create a data frame persons <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 30, 35), is_student = c(TRUE, FALSE, TRUE) ) print(persons) #> Typed Data Frame Summary: #> Base Frame Type: data.frame #> Dimensions: 3 rows x 4 columns #> #> Column Specifications: #> id : integer #> name : character #> age : numeric #> is_student : logical #> #> Frame Properties: #> Freeze columns : Yes #> Allow NA : Yes #> On violation : error #> #> Data Preview: #> id name age is_student #> 1 1 Alice 25 TRUE #> 2 2 Bob 30 FALSE #> 3 3 Charlie 35 TRUE # Invalid modification (throws error) try(persons$id <- letters[1:3]) #> Error : Property 'id' must be of type integer"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"additional-options","dir":"Articles","previous_headings":"Usage > Typed data.frame/data.tables","what":"Additional Options","title":"Introduction to interface","text":"","code":"PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical, gender = enum(\"M\", \"F\"), email = function(x) all(grepl(\"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$\", x)) # functions are applied to whole column ), freeze_n_cols = FALSE, row_callback = function(row) { if (row$age >= 40) { return(sprintf(\"Age must be less than 40 (got %d)\", row$age)) } if (row$name == \"Yanice\") { return(\"Name cannot be 'Yanice'\") } return(TRUE) }, allow_na = FALSE, on_violation = \"error\" ) df <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 35, 35), is_student = c(TRUE, FALSE, TRUE), gender = c(\"F\", \"M\", \"M\"), email = c(\"alice@test.com\", \"bob_no_valid@test.com\", \"charlie@example.com\") ) print(df) #> Typed Data Frame Summary: #> Base Frame Type: data.frame #> Dimensions: 3 rows x 6 columns #> #> Column Specifications: #> id : integer #> name : character #> age : numeric #> is_student : logical #> gender : Enum(M, F) #> email : custom function #> #> Frame Properties: #> Freeze columns : No #> Allow NA : No #> On violation : error #> #> Data Preview: #> id name age is_student gender email #> 1 1 TRUE 1 TRUE TRUE TRUE #> 2 1 TRUE 1 TRUE TRUE TRUE #> 3 1 TRUE 1 TRUE TRUE TRUE summary(df) #> id name age is_student #> Min. :1 Length:3 Min. :1 Mode:logical #> 1st Qu.:1 Class :character 1st Qu.:1 TRUE:3 #> Median :1 Mode :character Median :1 #> Mean :1 Mean :1 #> 3rd Qu.:1 3rd Qu.:1 #> Max. :1 Max. :1 #> gender.Length gender.Class gender.Mode email #> 1 -none- logical Length:3 #> 1 -none- logical Class :character #> 1 -none- logical Mode :character #> #> #> # Invalid row addition (throws error) try(rbind(df, data.frame( id = 4, name = \"David\", age = 500, is_student = TRUE, email = \"d@test.com\" ))) #> Error in rbind(deparse.level, ...) : Number of columns must match"},{"path":"https://dereckmezquita.github.io/interface/articles/intro-to-interface.html","id":"conclusion","dir":"Articles","previous_headings":"","what":"Conclusion","title":"Introduction to interface","text":"package provides powerful tools ensuring type safety validation R. defining interfaces, enums, typed functions, typed data frames, can create robust reliable data structures functions strict type constraints. vignette demonstrates basic usage capabilities package. details, refer package documentation examples provided source code.","code":""},{"path":"https://dereckmezquita.github.io/interface/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Dereck Mezquita. Author, maintainer.","code":""},{"path":"https://dereckmezquita.github.io/interface/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Mezquita, D. (2024). interface: Runtime Type System R. R package version 0.1.0. https://github.com/dereckmezquita/interface","code":"@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}, }"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"interface","dir":"","previous_headings":"","what":"Runtime Type System for R","title":"Runtime Type System for R","text":"interface package provides system defining implementing interfaces R, runtime type checking, bringing benefits statically-typed languages R zero dependencies. interface provides: Interfaces: Define implement interfaces type checking. Interfaces can extended nested. Typed Functions: Define functions strict type constraints. Typed Frames: Choose data.frame data.table column type constraints row validation. Enums: Define use enumerated types stricter type safety.","code":""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Runtime Type System for R","text":"install package, use following command:","code":"# Install the package from the source remotes::install_github(\"dereckmezquita/interface\")"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"getting-started","dir":"","previous_headings":"","what":"Getting started","title":"Runtime Type System for R","text":"Import package functions. Define interface implement :","code":"box::use(interface[ interface, type.frame, fun, enum ]) # Define an interface Person <- interface( name = character, age = numeric, email = character ) # Implement the interface john <- Person( name = \"John Doe\", age = 30, email = \"john@example.com\" ) print(john) #> Object implementing interface: #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled # interfaces are lists print(john$name) #> [1] \"John Doe\" # Modify the object john$age <- 10 print(john$age) #> [1] 10 # Invalid assignment (throws error) try(john$age <- \"thirty\") #> Error : Property 'age' must be of type numeric"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"extending-interfaces-and-nested-interfaces","dir":"","previous_headings":"Getting started","what":"Extending Interfaces and Nested Interfaces","title":"Runtime Type System for R","text":"Create nested extended interfaces:","code":"# Define nested interfaces Address <- interface( street = character, city = character, postal_code = character ) Scholarship <- interface( amount = numeric, status = logical ) # Extend interfaces Student <- interface( extends = c(Address, Person), student_id = character, scores = data.table::data.table, scholarship = Scholarship ) # Implement the extended interface john_student <- Student( name = \"John Doe\", age = 30, email = \"john@example.com\", street = \"123 Main St\", city = \"Small town\", postal_code = \"12345\", student_id = \"123456\", scores = data.table::data.table( subject = c(\"Math\", \"Science\"), score = c(95, 88) ), scholarship = Scholarship( amount = 5000, status = TRUE ) ) print(john_student) #> Object implementing interface: #> student_id: 123456 #> scores: Math #> scores: Science #> scores: 95 #> scores: 88 #> scholarship: #> street: 123 Main St #> city: Small town #> postal_code: 12345 #> name: John Doe #> age: 30 #> email: john@example.com #> Validation on access: Disabled"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"custom-validation-functions","dir":"","previous_headings":"Getting started","what":"Custom Validation Functions","title":"Runtime Type System for R","text":"Interfaces can custom validation functions:","code":"is_valid_email <- function(x) { grepl(\"[a-z|0-9]+\\\\@[a-z|0-9]+\\\\.[a-z|0-9]+\", x) } UserProfile <- interface( username = character, email = is_valid_email, age = function(x) is.numeric(x) && x >= 18 ) # Implement with valid data valid_user <- UserProfile( username = \"john_doe\", email = \"john@example.com\", age = 25 ) print(valid_user) #> Object implementing interface: #> username: john_doe #> email: john@example.com #> age: 25 #> Validation on access: Disabled # Invalid implementation (throws error) try(UserProfile( username = \"jane_doe\", email = \"not_an_email\", age = \"30\" )) #> Error : Errors occurred during interface creation: #> - Invalid value for property 'email': FALSE #> - Invalid value for property 'age': FALSE"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"typed-functions","dir":"","previous_headings":"Getting started","what":"Typed Functions","title":"Runtime Type System for R","text":"Define functions strict type constraints: Functions multiple possible return types:","code":"typed_fun <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x + y) } ) print(typed_fun(1, 2)) # [1] 3 #> [1] 3 try(typed_fun(\"a\", 2)) # Invalid call #> Error : Property 'x' must be of type numeric typed_fun2 <- fun( x = c(numeric, character), y = numeric, return = c(numeric, character), impl = function(x, y) { if (is.numeric(x)) { return(x + y) } else { return(paste(x, y)) } } ) print(typed_fun2(1, 2)) # [1] 3 #> [1] 3 print(typed_fun2(\"a\", 2)) # [1] \"a 2\" #> [1] \"a 2\""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"typed-data-frames-and-data-tables","dir":"","previous_headings":"Getting started","what":"Typed Data Frames and Data Tables","title":"Runtime Type System for R","text":"Create data frames column type constraints row validation: Additional options data frame validation:","code":"PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical ) ) # Create a data frame persons <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 30, 35), is_student = c(TRUE, FALSE, TRUE) ) print(persons) #> [1mTyped Data Frame Summary:[0m #> Base Frame Type: data.frame #> Dimensions: 3 rows x 4 columns #> #> [1mColumn Specifications:[0m #> id : integer #> name : character #> age : numeric #> is_student : logical #> #> [1mFrame Properties:[0m #> Freeze columns : Yes #> Allow NA : Yes #> On violation : error #> #> [1mData Preview:[0m #> id name age is_student #> 1 1 Alice 25 TRUE #> 2 2 Bob 30 FALSE #> 3 3 Charlie 35 TRUE # Invalid modification (throws error) try(persons$id <- letters[1:3]) #> Error in `$<-.typed_frame`(`*tmp*`, id, value = c(\"a\", \"b\", \"c\")) : #> object 'col_name' not found PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical, gender = enum(\"M\", \"F\"), email = function(x) all(grepl(\"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$\", x)) ), freeze_n_cols = FALSE, row_callback = function(row) { if (row$age >= 40) { return(sprintf(\"Age must be less than 40 (got %d)\", row$age)) } if (row$name == \"Yanice\") { return(\"Name cannot be 'Yanice'\") } return(TRUE) }, allow_na = FALSE, on_violation = \"error\" ) df <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 35, 35), is_student = c(TRUE, FALSE, TRUE), gender = c(\"F\", \"M\", \"M\"), email = c(\"alice@test.com\", \"bob_no_valid@test.com\", \"charlie@example.com\") ) print(df) #> [1mTyped Data Frame Summary:[0m #> Base Frame Type: data.frame #> Dimensions: 3 rows x 6 columns #> #> [1mColumn Specifications:[0m #> id : integer #> name : character #> age : numeric #> is_student : logical #> gender : Enum(M, F) #> email : custom function #> #> [1mFrame Properties:[0m #> Freeze columns : No #> Allow NA : No #> On violation : error #> #> [1mData Preview:[0m #> id name age is_student gender email #> 1 1 TRUE 1 TRUE TRUE TRUE #> 2 1 TRUE 1 TRUE TRUE TRUE #> 3 1 TRUE 1 TRUE TRUE TRUE summary(df) #> id name age is_student #> Min. :1 Length:3 Min. :1 Mode:logical #> 1st Qu.:1 Class :character 1st Qu.:1 TRUE:3 #> Median :1 Mode :character Median :1 #> Mean :1 Mean :1 #> 3rd Qu.:1 3rd Qu.:1 #> Max. :1 Max. :1 #> gender.Length gender.Class gender.Mode email #> 1 -none- logical Length:3 #> 1 -none- logical Class :character #> 1 -none- logical Mode :character #> #> #> # Invalid row addition (throws error) try(rbind(df, data.frame( id = 4, name = \"David\", age = 50, is_student = TRUE, email = \"d@test.com\" ))) #> Error in rbind(deparse.level, ...) : Number of columns must match"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"enums","dir":"","previous_headings":"Getting started","what":"Enums","title":"Runtime Type System for R","text":"Define enums categorical variables; safe use protect value modified invalid options. enum function creates generator used create enum object. can used standalone part interface.","code":"Colour <- enum(\"red\", \"green\", \"blue\") # Create an enum object colour <- Colour(\"red\") print(colour) #> Enum: red colour$value <- \"green\" print(colour) #> Enum: green # Invalid modification (throws error) try(colour$value <- \"yellow\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue # Use in an interface Car <- interface( make = enum(\"Toyota\", \"Ford\", \"Chevrolet\"), model = character, colour = Colour ) # Implement the interface car1 <- Car( make = \"Toyota\", model = \"Corolla\", colour = \"red\" ) print(car1) #> Object implementing interface: #> make: Toyota #> model: Corolla #> colour: red #> Validation on access: Disabled # Invalid implementation (throws error) try(Car( make = \"Honda\", model = \"Civic\", colour = \"yellow\" )) #> Error : Errors occurred during interface creation: #> - Invalid enum value for property 'make': Invalid value. Must be one of: Toyota, Ford, Chevrolet #> - Invalid enum value for property 'colour': Invalid value. Must be one of: red, green, blue # Invalid modification (throws error) try(car1$colour$value <- \"yellow\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue try(car1$make$value <- \"Honda\") #> Error in `$<-.enum`(`*tmp*`, value, value = \"Honda\") : #> Invalid value. Must be one of: Toyota, Ford, Chevrolet"},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"conclusion","dir":"","previous_headings":"","what":"Conclusion","title":"Runtime Type System for R","text":"interface package provides powerful tools ensuring type safety validation R. defining interfaces, typed functions, typed data frames, can create robust reliable data structures functions strict type constraints. details, refer package documentation.","code":""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"license","dir":"","previous_headings":"","what":"License","title":"Runtime Type System for R","text":"package licensed MIT License.","code":""},{"path":"https://dereckmezquita.github.io/interface/index.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Runtime Type System for R","text":"use package research work, please cite : Mezquita, D. (2024). interface: Runtime Type System R. R package version 0.1.0. https://github.com/dereckmezquita/interface","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Get value from enum object — $.enum","title":"Get value from enum object — $.enum","text":"Retrieves value enum object.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get value from enum object — $.enum","text":"","code":"# S3 method for class 'enum' x$name"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get value from enum object — $.enum","text":"x enum object name name field access (\"value\")","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get value from enum object — $.enum","text":"value enum object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get value from enum object — $.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") my_color <- Colors(\"red\") my_color$value # \"red\" #> [1] \"red\""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.interface_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Get a property from an interface object — $.interface_object","title":"Get a property from an interface object — $.interface_object","text":"Get property interface object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.interface_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get a property from an interface object — $.interface_object","text":"","code":"# S3 method for class 'interface_object' x$name"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-.interface_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get a property from an interface object — $.interface_object","text":"x interface object name name property get","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Set value of enum object — $<-.enum","title":"Set value of enum object — $<-.enum","text":"Sets value enum object. new value must one valid enum values.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Set value of enum object — $<-.enum","text":"","code":"# S3 method for class 'enum' x$name <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Set value of enum object — $<-.enum","text":"x enum object name name field set (\"value\") value new value set","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Set value of enum object — $<-.enum","text":"updated enum object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Set value of enum object — $<-.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") my_color <- Colors(\"red\") my_color$value <- \"blue\" # Valid assignment try(my_color$value <- \"yellow\") # This will raise an error #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.interface_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Set a property in an interface object — $<-.interface_object","title":"Set a property in an interface object — $<-.interface_object","text":"Set property interface object","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.interface_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Set a property in an interface object — $<-.interface_object","text":"","code":"# S3 method for class 'interface_object' x$name <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.interface_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Set a property in an interface object — $<-.interface_object","text":"x interface object name name property set value new value property","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify a typed data frame using $ — $<-.typed_frame","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"Allows modifying typed data frame using $ operator, validation checks.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"","code":"# S3 method for class 'typed_frame' x$col_name <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"x typed data frame. col_name name column modify add. value new value assign.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/cash-set-.typed_frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify a typed data frame using $ — $<-.typed_frame","text":"modified typed data frame.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an enumerated type — enum","title":"Create an enumerated type — enum","text":"Creates enumerated type fixed set possible values. function returns enum generator, can used create enum objects values restricted specified set.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an enumerated type — enum","text":"","code":"enum(...)"},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an enumerated type — enum","text":"... possible values enumerated type. unique character strings.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an enumerated type — enum","text":"function (enum generator) creates enum objects defined type.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/reference/enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create an enumerated type — enum","text":"","code":"# Create an enum type for colors Colors <- enum(\"red\", \"green\", \"blue\") # Create enum objects my_color <- Colors(\"red\") print(my_color) # Output: Enum: red #> Enum: red # Trying to create an enum with an invalid value will raise an error try(Colors(\"yellow\")) #> Error in Colors(\"yellow\") : #> Invalid value. Must be one of: red, green, blue # Enums can be used in interfaces ColoredShape <- interface( shape = character, color = Colors ) my_shape <- ColoredShape(shape = \"circle\", color = \"red\") # Modifying enum values my_shape$color$value <- \"blue\" # This is valid try(my_shape$color$value <- \"yellow\") # This will raise an error #> Error in `$<-.enum`(`*tmp*`, value, value = \"yellow\") : #> Invalid value. Must be one of: red, green, blue"},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Equality comparison for enum objects — ==.enum","title":"Equality comparison for enum objects — ==.enum","text":"Compares two enum objects enum object character value.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Equality comparison for enum objects — ==.enum","text":"","code":"# S3 method for class 'enum' e1 == e2"},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Equality comparison for enum objects — ==.enum","text":"e1 First enum object e2 Second enum object character value","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Equality comparison for enum objects — ==.enum","text":"Logical value indicating whether two objects equal","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/equals-.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Equality comparison for enum objects — ==.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") color1 <- Colors(\"red\") color2 <- Colors(\"blue\") color1 == color2 # FALSE #> [1] FALSE color1 == Colors(\"red\") # TRUE #> [1] TRUE color1 == \"red\" # TRUE #> [1] TRUE"},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a typed function — fun","title":"Create a typed function — fun","text":"Defines function specified parameter types return type. Ensures function's arguments return value adhere specified types.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a typed function — fun","text":"","code":"fun(...)"},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a typed function — fun","text":"... Named arguments defining function parameters types, including 'return' expected return type(s) 'impl' function implementation.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a typed function — fun","text":"typed function enforces type constraints parameters return value.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a typed function — fun","text":"`fun` function allows define function strict type checking parameters return value. ensures function receives arguments correct types returns value expected type. 'return' 'impl' arguments included ... parameter list.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/fun.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a typed function — fun","text":"","code":"# Define a typed function that adds two numbers add_numbers <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x + y) } ) # Valid call print(add_numbers(1, 2)) # [1] 3 #> [1] 3 # Invalid call (throws error) try(add_numbers(\"a\", 2)) #> Error : Property 'x' must be of type numeric # Define a typed function with multiple return types concat_or_add <- fun( x = c(numeric, character), y = numeric, return = c(numeric, character), impl = function(x, y) { if (is.numeric(x)) { return(x + y) } else { return(paste(x, y)) } } ) # Valid calls print(concat_or_add(1, 2)) # [1] 3 #> [1] 3 print(concat_or_add(\"a\", 2)) # [1] \"a 2\" #> [1] \"a 2\""},{"path":"https://dereckmezquita.github.io/interface/reference/handle_violation.html","id":null,"dir":"Reference","previous_headings":"","what":"Handle violations based on the specified action — handle_violation","title":"Handle violations based on the specified action — handle_violation","text":"Handles violations either throwing error, issuing warning, nothing, depending specified action.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/handle_violation.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Handle violations based on the specified action — handle_violation","text":"","code":"handle_violation(message, action)"},{"path":"https://dereckmezquita.github.io/interface/reference/handle_violation.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Handle violations based on the specified action — handle_violation","text":"message error message handled. action action take: \"error\", \"warning\", \"silent\".","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":null,"dir":"Reference","previous_headings":"","what":"Define an interface — interface","title":"Define an interface — interface","text":"interface defines structure specified properties types validation functions. useful ensuring objects adhere particular format type constraints.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Define an interface — interface","text":"","code":"interface(..., validate_on_access = FALSE, extends = list())"},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Define an interface — interface","text":"... Named arguments defining properties types validation functions. validate_on_access Logical, whether validate properties access (default: FALSE). extends list interfaces interface extends.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Define an interface — interface","text":"function create objects implement defined interface.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/interface.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Define an interface — interface","text":"","code":"# Define an interface for a person Person <- interface( name = character, age = numeric, email = character ) # Create an object that implements the Person interface john <- Person( name = \"John Doe\", age = 30, email = \"john@example.com\" ) # Using enum in an interface Colors <- enum(\"red\", \"green\", \"blue\") ColoredShape <- interface( shape = character, color = Colors ) my_shape <- ColoredShape(shape = \"circle\", color = \"red\") # In-place enum declaration Car <- interface( make = character, model = character, color = enum(\"red\", \"green\", \"blue\") ) my_car <- Car(make = \"Toyota\", model = \"Corolla\", color = \"red\")"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for enum objects — print.enum","title":"Print method for enum objects — print.enum","text":"Prints human-readable representation enum object.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for enum objects — print.enum","text":"","code":"# S3 method for class 'enum' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for enum objects — print.enum","text":"x enum object ... Additional arguments (used)","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for enum objects — print.enum","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") my_color <- Colors(\"red\") print(my_color) # Output: Enum: red #> Enum: red"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for enum generators — print.enum_generator","title":"Print method for enum generators — print.enum_generator","text":"Prints human-readable representation enum generator, showing possible values.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for enum generators — print.enum_generator","text":"","code":"# S3 method for class 'enum_generator' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for enum generators — print.enum_generator","text":"x enum generator function ... Additional arguments (used)","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.enum_generator.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for enum generators — print.enum_generator","text":"","code":"Colors <- enum(\"red\", \"green\", \"blue\") print(Colors) # Output: Enum generator: red, green, blue #> Enum generator: red, green, blue"},{"path":"https://dereckmezquita.github.io/interface/reference/print.interface_object.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for interface objects — print.interface_object","title":"Print method for interface objects — print.interface_object","text":"Print method interface objects","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.interface_object.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for interface objects — print.interface_object","text":"","code":"# S3 method for class 'interface_object' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.interface_object.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for interface objects — print.interface_object","text":"x object implementing interface ... Additional arguments (used)","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for typed data frames — print.typed_frame","title":"Print method for typed data frames — print.typed_frame","text":"Provides custom print method typed data frames, displaying properties validation status.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for typed data frames — print.typed_frame","text":"","code":"# S3 method for class 'typed_frame' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for typed data frames — print.typed_frame","text":"x typed data frame. ... Additional arguments passed print.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for typed functions — print.typed_function","title":"Print method for typed functions — print.typed_function","text":"Provides custom print method typed functions, displaying parameter types return type.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for typed functions — print.typed_function","text":"","code":"# S3 method for class 'typed_function' print(x, ...)"},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for typed functions — print.typed_function","text":"x typed function. ... Additional arguments (used).","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/print.typed_function.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for typed functions — print.typed_function","text":"","code":"# Define a typed function multiply <- fun( x = numeric, y = numeric, return = numeric, impl = function(x, y) { return(x * y) } ) # Print the typed function print(multiply) #> Typed function: #> Arguments: #> x: function (length = 0L) #> x: .Internal(vector(\"double\", length)) #> y: function (length = 0L) #> y: .Internal(vector(\"double\", length)) #> Return type: function (length = 0L) #> Return type: .Internal(vector(\"double\", length))"},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Combine typed data frames row-wise — rbind.typed_frame","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"function combines multiple typed data frames row-wise, ensuring type consistency applying row validation rules. extends base rbind function adding type checks row validation based specified rules typed data frames.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"","code":"# S3 method for class 'typed_frame' rbind(..., deparse.level = 1)"},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"... Typed data frames combine. deparse.level See rbind.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"combined typed data frame.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/rbind.typed_frame.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Combine typed data frames row-wise — rbind.typed_frame","text":"version rbind typed_frame performs extra type checking row validation ensure consistency adherence specified rules. Refer base rbind documentation additional details combining data frames: rbind.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify a typed data frame using [ ] — [<-.typed_frame","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"Allows modifying typed data frame using [ ] operator, validation checks.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"","code":"# S3 method for class 'typed_frame' x[i, j] <- value"},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"x typed data frame. Row index. j Column index name. value new value assign.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/subset-.typed_frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify a typed data frame using [ ] — [<-.typed_frame","text":"modified typed data frame.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a typed data frame — type.frame","title":"Create a typed data frame — type.frame","text":"Creates data frame specified column types validation rules. Ensures data frame adheres specified structure validation rules creation modification.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a typed data frame — type.frame","text":"","code":"type.frame( frame, col_types, freeze_n_cols = TRUE, row_callback = NULL, allow_na = TRUE, on_violation = c(\"error\", \"warning\", \"silent\") )"},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a typed data frame — type.frame","text":"frame base data structure (e.g., data.frame, data.table). col_types list column types validators. freeze_n_cols Logical, whether freeze number columns (default: TRUE). row_callback function validate process row (optional). allow_na Logical, whether allow NA values (default: TRUE). on_violation Action take violation: \"error\", \"warning\", \"silent\" (default: \"error\").","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a typed data frame — type.frame","text":"function creates typed data frames.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a typed data frame — type.frame","text":"`type.frame` function defines blueprint data frame, specifying types columns optional validation rules rows. data frame created modified using blueprint, ensures data adheres specified rules.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/type.frame.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a typed data frame — type.frame","text":"","code":"# Define a typed data frame PersonFrame <- type.frame( frame = data.frame, col_types = list( id = integer, name = character, age = numeric, is_student = logical ) ) # Create a data frame persons <- PersonFrame( id = 1:3, name = c(\"Alice\", \"Bob\", \"Charlie\"), age = c(25, 30, 35), is_student = c(TRUE, FALSE, TRUE) ) print(persons) #> Typed Data Frame Summary: #> Base Frame Type: data.frame #> Dimensions: 3 rows x 4 columns #> #> Column Specifications: #> id : integer #> name : character #> age : numeric #> is_student : logical #> #> Frame Properties: #> Freeze columns : Yes #> Allow NA : Yes #> On violation : error #> #> Data Preview: #> id name age is_student #> 1 1 Alice 25 TRUE #> 2 2 Bob 30 FALSE #> 3 3 Charlie 35 TRUE # Invalid modification (throws error) try(persons$id <- letters[1:3]) #> Error : Property 'id' must be of type integer # Adding a column (throws error if freeze_n_cols is TRUE) try(persons$yeet <- letters[1:3]) #> Error in `$<-.typed_frame`(`*tmp*`, yeet, value = c(\"a\", \"b\", \"c\")) : #> Adding new columns is not allowed when freeze_n_cols is TRUE"},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate a property against a given type or validation function — validate_property","title":"Validate a property against a given type or validation function — validate_property","text":"Validates property ensure matches expected type satisfies given validation function.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate a property against a given type or validation function — validate_property","text":"","code":"validate_property(name, value, validator)"},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate a property against a given type or validation function — validate_property","text":"name name property validated. value value property. validator expected type custom validation function.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/validate_property.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate a property against a given type or validation function — validate_property","text":"NULL validation passes, otherwise error message.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":null,"dir":"Reference","previous_headings":"","what":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"Modifies user-defined function wrap body () call, ensuring returns single logical value instead vector. uses bquote() create new body function. .() inside bquote() inserts original body function. () function wraps around original body.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"","code":"wrap_fun_in_all(user_fun)"},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"user_fun user-defined function.","code":""},{"path":"https://dereckmezquita.github.io/interface/reference/wrap_fun_in_all.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Modify a user-defined function to return a single logical value — wrap_fun_in_all","text":"modified function.","code":""},{"path":[]},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"breaking-changes-0-1-0","dir":"Changelog","previous_headings":"","what":"BREAKING CHANGES","title":"interface v0.1.0 (in development)","text":"N/","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"new-features-0-1-0","dir":"Changelog","previous_headings":"","what":"NEW FEATURES","title":"interface v0.1.0 (in development)","text":"Implemented core functionality defining implementing interfaces. Added support optional runtime type checking. Included support nested interfaces custom validation functions. Created comprehensive documentation vignettes. Implemented enum functionality defining enumerated types. Added typed functions strict type constraints. Implemented typed data frames data tables column type constraints row validation.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"improvements-0-1-0","dir":"Changelog","previous_headings":"","what":"IMPROVEMENTS","title":"interface v0.1.0 (in development)","text":"Enhanced package structure organization. Improved error handling informative error messages. Optimized performance type checking operations.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"documentation-0-1-0","dir":"Changelog","previous_headings":"","what":"DOCUMENTATION","title":"interface v0.1.0 (in development)","text":"Created detailed vignettes package usage examples. Improved function documentation examples clearer explanations. Added README installation instructions quick start guide.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"development-0-1-0","dir":"Changelog","previous_headings":"","what":"DEVELOPMENT","title":"interface v0.1.0 (in development)","text":"Set continuous integration GitHub Actions. Implemented comprehensive test suite using testthat. Ensured CRAN policy compliance.","code":""},{"path":"https://dereckmezquita.github.io/interface/news/index.html","id":"notes-0-1-0","dir":"Changelog","previous_headings":"","what":"NOTES","title":"interface v0.1.0 (in development)","text":"first release interface package. package compatible R versions 4.1.0 .","code":""}]