| Title: | API to 'Python' Library 'pysd' |
|---|---|
| Description: | Using the R package 'reticulate', this package creates an interface to the 'pysd' toolset. The package provides an R interface to a number of 'pysd' functions, and can read files in 'Vensim' 'mdl' format, and 'xmile' format. The resulting simulations are returned as a 'tibble', and from that the results can be processed using 'dplyr' and 'ggplot2'. The package has been tested using 'python3'. |
| Authors: | Jim Duggan [aut, cre] |
| Maintainer: | Jim Duggan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-26 08:22:30 UTC |
| Source: | https://github.com/jimduggan/pysd2r |
get_doc() Get mode variable names
get_doc(o)get_doc(o)
o |
is the ipysd S3 object |
tibble
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) mdoc <- get_doc(py) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) mdoc <- get_doc(py) ## End(Not run)
get_timestep uses pysd to fetch the time step from the model
get_final_time(o)get_final_time(o)
o |
is the ipysd S3 object |
As it's a generic function, this call is dispatched to set_component.isdpy
The finaltime
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) final_time <- get_final_time(py) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) final_time <- get_final_time(py) ## End(Not run)
get_initial_time uses pysd to fetch the time step from the model
get_initial_time(o)get_initial_time(o)
o |
is the ipysd S3 object |
As it's a generic function, this call is dispatched to set_component.isdpy
The initial time
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) initial_time <- get_initial_time(py) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) initial_time <- get_initial_time(py) ## End(Not run)
get_python_info returns information on what version of python
is being used with reticulate
get_python_info()get_python_info()
python information
## Not run: get_python_info() ## End(Not run)## Not run: get_python_info() ## End(Not run)
get_timestep uses pysd to fetch the time step from the model
get_timestep(o)get_timestep(o)
o |
is the ipysd S3 object |
As it's a generic function, this call is dispatched to set_component.isdpy
The simulation time step
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) time_step <- get_timestep(py) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) time_step <- get_timestep(py) ## End(Not run)
pysd_connect returns a ipysd object to the calling program.
This object will contain a link variable to pysd and will subsequently
store a reference to the simulation model in pysd.
pysd_connect()pysd_connect()
The result is used as a parameter for read_vensim() & read_xmile() functions
An S3 object of class ipysd
## Not run: py pysd_connect() ## End(Not run)## Not run: py pysd_connect() ## End(Not run)
read_vensim() calls pysd.read_vensim() and stores the object for
further use. This is a key object, as it relates to a model and it can
support a number of functions (e.g. model run, parameter changes)
read_vensim(o, file)read_vensim(o, file)
o |
is the ipysd S3 object |
file |
is the filename and path for the Vensim mdl file that needs to be simulated |
The result is used as a parameter for simulation calls.
As it's a generic function, this call is dispatched to read_vensim.isdpy
An S3 object of class ipysd that will contain a reference to the model
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() read_vensim(py, target) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() read_vensim(py, target) ## End(Not run)
read_xmile() calls pysd.read_xmile() and stores the object for
further use. This is a key object, as it relates to a model and it can
support a number of functions (e.g. model run, parameter changes)
read_xmile(o, file)read_xmile(o, file)
o |
is the ipysd S3 object |
file |
is the filename and path for the Vensim mdl file that needs to be simulated |
The result is used as a parameter for simulation calls.
As it's a generic function, this call is dispatched to read_xmile.isdpy
An S3 object of class ipysd that will contain a reference to the model
## Not run: target <- system.file("models/xmile", "Population.xmile", package = "pysd2r") py <- pysd_connect() read_xmile(py, target) ## End(Not run)## Not run: target <- system.file("models/xmile", "Population.xmile", package = "pysd2r") py <- pysd_connect() read_xmile(py, target) ## End(Not run)
reload_model() Reloads the model
reload_model(o)reload_model(o)
o |
is the ipysd S3 object |
ipysd object
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) set_time_values(py,0,10,0.5) py<-reload_model(py) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) set_time_values(py,0,10,0.5) py<-reload_model(py) ## End(Not run)
run_model() calls run in pysd and returns all
the simulation output in tidy data format (tibble)
run_model(o)run_model(o)
o |
is the ipysd S3 object |
As it's a generic function, this call is dispatched to run_model.isdpy
tibble containing the simulation results
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) results <- run_model(py) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) results <- run_model(py) ## End(Not run)
set_components() calls .set_components() and changes
a resulting parameter in the model
set_components(o, vals)set_components(o, vals)
o |
is the ipysd S3 object |
vals |
contains a list with the parameter and value to be changed |
As it's a generic function, this call is dispatched to set_component.isdpy
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) results <- run_model(py) l <- list("Growth Fraction"=0.02) set_components(py,l) out2 <- run_model(py) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) results <- run_model(py) l <- list("Growth Fraction"=0.02) set_components(py,l) out2 <- run_model(py) ## End(Not run)
set_time_valuesl() sets the simulation times and DT
set_time_values(o, init, final, DT)set_time_values(o, init, final, DT)
o |
is the ipysd S3 object |
init |
is the initial time |
final |
is the final time |
DT |
is the time step |
## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) set_time_values(py,0,10,0.5) ## End(Not run)## Not run: target <- system.file("models/vensim", "Population.mdl", package = "pysd2r") py <- pysd_connect() py <- read_vensim(py, target) set_time_values(py,0,10,0.5) ## End(Not run)