You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CRAN portability changes & Update R interface (#191)
* Fix compilation of SWIG generated C file for R
This commit renames paramater names that clash with typenames
(i.e. `model`, `hospital`, `ward`)
When running `swig -r covid19.i`, swig parses the parameter names of C
functions and uses those same parameter names when generating wrapper
functions.
Example:
void foo( model* model );
Becomes:
SEXP R_swig_foo ( SEXP model, SEXP s_swig_copy)
{
double result;
model *arg1 = (model *) 0 ;
...
}
GCC will fail to compile the variable declaration of arg1, because model
is a variable name so `model *arg1` looks like a multiplication op.
* MVP for R Source Package
This generates a minimal R source package named covid19.tar.gz.
Tested on Cygwin64 using `R CMD INSTALL -d src/covid19.tar.gz`.
Details:
- Add generated build files to .gitignore
- Add build rule for covid.R, covid19_wrap_R.c (generated from SWIG)
- Add build rule for DESCRIPTION (depends on source file: DESCRIPTION.in)
- Add build rule for NAMESPACE (depends on generated file: covid.R)
- Add build rule for covid19.tar.gz
* Add Makevars.win to build R pkg on Windows
* Commit generated source files
This should facilitate building the package using `R CMD build ...`
Added a .PHONY build rule `update_R_files` in Makefile to regenerate these
source files.
* Add build-Rpkg-win.bat script
This builds an R binary package for Windows.
* Fix autogeneration of NAMESPACE
* Rename R package to OpenABMCovid19
* Add Makefile at root to wrap `R CMD`
This creates three phony targets:
- Rbuild: Generates package content (e.g. runs SWIG source generation) and
then calls `R CMD build ...`
- Rinstall: Builds `Rbuild` and then locally installs the package with
`R CMD INSTALL ...`
- Rcheck: Builds `Rbuild` and then runs `R CMD check ...`
* Fix macOS R build with non-standard Homebrew install
* Remove unused update_R_files phony target
* Fix compilation from SWIG generated C file
If the typename and variable name clash then SWIG will generate C source that
does not compile.
* Remove empty line
* Fix R CMD check warnings
* Undocumented exports in NAMESPACE.
* Functions from package 'methods' used but not imported.
* Generated SWIG R source using `.Call` without `PACKAGE` param.
* src/Makevars uses GNUmake extensions.
* Link to static lib (facilitates redist).
* Fix 'Undocumented S4 methods' R check warning
* Fix `R CMD check` NOTE about missing R functions
* Add unnecessary dtors: required, because SWIG generates unnecessary ctors
* Add unusable setter functions: calls stop() when trying to set a constant
* Fix last remaining `R CMD check` warning
* Exclude main.c from compilation (not required)
* Compile with `-DBUILD_RPKG` define flag
* Use `Rprintf()` instead of `printf()`
* Use `Rf_error()` instead of `exit()`
* Add convenience wrapper `printf_w`.
* Add `#define printf print_w`
* Ignore SWIG ctors for internal types
These types are memory managed by create_model() and destroy_model() so SWIG
doesn't need to create bindings for allocating and freeing these structs.
* Fix new warnings and notes from `R check`
- no visible global function definition for 'NEWLY_INFECTED_STATES_set'
- no visible binding for global variable 'delete_incomplete_gamma_p_params'
- undocumented S4 methods ('$', '$<-', '[[<-')
All user-level objects in a package (including S4 classes and methods)
* Add missing #include <stdarg.h>
* Add RStudio project and simplify Makefile
The Makefile now has a build rule `Rswig` to generate source files from SWIG.
This removes the DESCRIPTION.in -> DESCRIPTION build rule (just commit file
DESCRIPTION instead); this build rule was more trouble than it's worth.
Updated the README to reflect this changes to the Makefile.
Also make git and R ignore RStudio files.
* Add missing backslash in Makefile
* Build with --no-multiarch in RStudio
Also add files to .gitignore and .Rbuildignore
* Fix the DLL loading
- Link statically to GSL.
(otherwise R cannot find libgsl-25.dll and libgslcblas-0.dll)
- Call useDynLib in NAMESPACE file.
* Fix a bug with .libPaths() with Rtools make
* Add Parameters R6 class with rudimentary tests
* Add variable arg list to print_exit
- Tell GCC to validate printf formats for print_exit and print_w.
- Make read_param_file output the input_param_file on fopen failure
(useful for debugging).
* Mute an `R CMD check` note
* Use Roxygen2 to generate R documentation
* Implement and test read_hospital_param_file
* Set output_file_dir and use more verbose tests
- Edit SWIG's buggy getter function in the generated R source.
- Set c_params$output_file_dir.
- Add test cases that check the c_param initial values.
* Add Parameters::set_param and get_param
* Prevent some unnecessary rebuild for Rman
* Implement Parameters$read_household_demographics
- Implement both file-path and R data-frame inputs.
- Add private `get_REFERENCE_HOUSEHOLDS` for testing.
- Add a test case for household demographics file-path.
- Add a test case for household demographics R data-frame.
* Speed up get_REFERENCE_HOUSEHOLDS
The previous implementation would create an empty data.frame and then append
rows one-by-one (very slow). The new implementation allocated a temporary
matrix the correct size and then converts that into a data.frame.
The matrix -> data.frame conversion is still slow, but overall it's faster.
* Put class Model & Parameters in seperate files
* Fix build errors
* Update all timestamps in `make Rman`
Roxygen2 sometimes only updates some .Rd files, which can confuse `make`.
Example: if Roxygen2 updates the timestamp of Parameters.Rd but not Model.Rd,
then Model.Rd will always be considering "out of date" but Roxygen2 will
never touch the file. Hence, `make Rman` might run devtools::document()
needlessly.
Calling `touch` guarantees this output when running `make Rman` twice:
make: Nothing to be done for 'Rman'
* Rename read-only.R -> util.R
- Move `make_integer` into from Parameters.R into util.R
- Add R/util.R as a target dependency in Makefile
* Fix `R CMD check` errors
* Add placeholder methods and tests
* Implement set_demographic_household_table
* Implement set_occupation_network_table
* Implement Parameters::return_param_object
* Add placeholder methods for Model class
* Implement risk setters and getters.
Also a AgeGroups list and fix documentation
* Remove Model's finalizer
This isn't necessary because SWIG already adds an S4 finalizer to call
delete_model (which calls destroy_model). Calling destroy_model twice causes
a crash.
* Implement trivial methods
* Add get_base_param_from_enum in R/util.R
This is the same as `_get_base_param_from_enum` in src/COVID19/model.py
Add a basic test for this: tests/testthat/test-util.R
Bonus:
- Fix minor errors in R/Model.R
- Rename AgeGroups to AgeGroupEnum
* Implement set/get param for C arrays
* Implement Model param set/update
- Add SAFE_UPDATE_PARAMS
- Add get for it in tests/testthat/test-Model.R
- Merge risk tests in tests/testthat/test-Model.R (faster performance)
- Rename AgeGroups to AgeGroupEnum in documentation
* Merge Model tests together in 1 test
Model$new is slow, so use 1 test_that to speed up iteration cycle.
* Implement Model$add_user_network
* Sync with PR #180
- Fix new compilation errors with `swig -r ...`
- Add new NETWORK_CONSTRUCTIONS to NAMESPACE
- Add new placeholder methods in Model.R
* Implement set_app_users and get_app_users
- Add get_app_user_by_index in params.h
SWIG's R interface doesn't allow modifying an input C array (the SWIG
wrapper allocates a new temporary buffer).
- Add a basic test (reverse the status app on/off)
* Add and implement Network class
Implement network methods in Model class
* Implement Model$get_network_ids
- Add C API `get_network_id_by_index`
(SWIG doesn't allow mutating C array parameters with R)
- Bugfixes in Network class
* Implement Model one_time_step_result()
Add test for one_time_step and one_time_step_result.
* Add untested Simulation.R
* Tidy up documentation
- Use `\code{\link{}}` to refer to classes & enums.
- Make Model$one_time_step_result() return a vector instead of a list.
- Make the enums vectors instead of lists.
- Fix other errors in documentation.
* Fix bugs in Simulation.R
- Add tests for Simulation.R
- Rename Model$one_time_step_result ('result' -> 'results')
* Fix `R CMD check` warnings and errors
Only errors is tests failing in 32-bit arch (works in 64-bit).
Likely caused by a memory stomp in the C code on 32 bit systems.
* Make R package more portable
- Fix 1 `R CMD check` NOTE: Reference to stdout.
- Fix sed usage on macOS.
- Remove Makevars, replaced with Makevars.in and configure that searches for
GNU GSL and generates system-specific Makevar file.
- Add package-for-CRAN.sh: utility script for generating source files (SWIG,
configure, Roxygen) before packaging.
- Update .Rbuildignore and .gitignore
* Use LIB_GSL on Windows
Windows doesn't use the configure script to find GNU GSL. CRAN maintainers
wants us to use environment variable to link to GSL. I've added a test BATCH
script to check that the package builds with LIB_GSL on Windows.
* Implement model.py's vaccination API
Add:
Model$seed_infect_by_idx
Model$vaccinate_individual
Model$vaccinate_schedule
Class VaccineSchedule
enum VACCINE_TYPES
enum VACCINE_STATUS
0 commit comments