simulation_modification: Modify the particles in a simulation

simulation_modificationR Documentation

Modify the particles in a simulation


The particles that are modelled in a simulation are encoded as a tbl_graph, giving support for the particles as well as their interactions (nodes and edges in graph parlor). A simulation supports a subset of the tidygraph/dplyr verbs in order to allow modification of the particles after they have been included in the simulation. In general it is possible to add and remove particles and interactions as well as modify the metadata associated with them. The API follows the tidygraph API where activate() is used to select either particles or interactions and subsequent operations are thus related to the last activated datatype. The simulation is automatically retrained after modifying the state of the particles and their interactions.


add_particles(.data, ..., interactions = NULL, setup = NULL)

replace_particles(.data, particles, setup = NULL)

add_interaction(.data, ...)



A simulation object


Parameters passed on to the main verbs in tidygraph/dplyr


A data.frame of interactions/edges to add along with the particles


A function to calculate the starting conditions for the particles. It receives all particles with the current position and velocity encoded in the x, y, x_vel, and y_vel columns. New particle will have NA. The function must return a position and velocity for all particles even though the values for the current particles will be discarded. If NULL it will use the genesis function used when creating the simulation.


A tbl_graph or an object coercible to one


A simulation object

See Also

dplyr::mutate(), dplyr::mutate_at(), dplyr::mutate_all(), dplyr::filter(), dplyr::slice(), tidygraph::activate(), tidygraph::bind_nodes(), tidygraph::bind_edges()

particles documentation built on Aug. 19, 2022, 5:06 p.m.