Skip to content

Commit

Permalink
Removing dangling calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jun 20, 2024
1 parent 476a6ea commit 97e074a
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 55 deletions.
1 change: 0 additions & 1 deletion R/agents.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ stopifnot_agent <- function(x) {
#' @param d,directed Logical scalar. Whether the graph is directed or not.
#' @param p Probability of rewiring.
#' @export
#' @aliases agents
#' @return
#' - The 'agents_smallworld' function returns a model with the agents
#' loaded.
Expand Down
4 changes: 2 additions & 2 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ print_agent_tools_cpp <- function(tools) {
.Call(`_epiworldR_print_agent_tools_cpp`, tools)
}

set_distribution_tool_cpp <- function(tool, model, tfun) {
.Call(`_epiworldR_set_distribution_tool_cpp`, tool, model, tfun)
set_distribution_tool_cpp <- function(tool, distfun) {
.Call(`_epiworldR_set_distribution_tool_cpp`, tool, distfun)
}

distribute_tool_randomly_cpp <- function(prevalence, as_proportion) {
Expand Down
14 changes: 8 additions & 6 deletions R/entity.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ stopifnot_entity <- function(entity) {
}
}

stopifnot_entity_distfun <- function(dist_fun) {
if (!inherits(dist_fun, "epiworld_distribution_entity")) {
stop("Argument 'dist_fun' must be a distribution function.")
stopifnot_entity_distfun <- function(distfun) {
if (!inherits(distfun, "epiworld_distribution_entity")) {
stop("Argument 'distfun' must be a distribution function.")

Check warning on line 10 in R/entity.R

View check run for this annotation

Codecov / codecov/patch

R/entity.R#L9-L10

Added lines #L9 - L10 were not covered by tests
}
}

Expand Down Expand Up @@ -92,6 +92,8 @@ print.epiworld_entities <- function(x, ...) {
#' @param prevalence Numeric scalar. Prevalence of the entity.
#' @param as_proportion Logical scalar. If `TRUE`, `prevalence` is interpreted
#' as a proportion.
#' @param to_unassigned Logical scalar. If `TRUE`, the entity is added to the
#' unassigned pool.
#' @return
#' - The function `entity` creates an entity object.
#' @rdname entities
Expand Down Expand Up @@ -280,14 +282,14 @@ distribute_entity_to_set <- function(

#' @export
#' @rdname entities
#' @param dist_fun Distribution function object of class `epiworld_distribution_entity`.
#' @param distfun Distribution function object of class `epiworld_distribution_entity`.
set_distribution_entity <- function(
entity,
dist_fun
distfun
) {

stopifnot_entity(entity)
stopifnot_entity_distfun(dist_fun)
stopifnot_entity_distfun(distfun)
set_distribution_entity_cpp(entity, distribution)

Check warning on line 293 in R/entity.R

View check run for this annotation

Codecov / codecov/patch

R/entity.R#L291-L293

Added lines #L291 - L293 were not covered by tests

invisible(entity)

Check warning on line 295 in R/entity.R

View check run for this annotation

Codecov / codecov/patch

R/entity.R#L295

Added line #L295 was not covered by tests
Expand Down
22 changes: 18 additions & 4 deletions R/functions-renamed.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
#' @name epiworldR-deprecated
NULL

#' @param n Deprecated. Either set the prevalence during the tool/virus
#' initialization or use `set_prevalence_tool`/`set_prevalence_virus`.
#' @param n Deprecated.
#' @export
#' @rdname epiworldR-deprecated
add_tool_n <- function(model, tool, n) {

.Deprecated(new = "add_tool")

Check warning on line 18 in R/functions-renamed.R

View check run for this annotation

Codecov / codecov/patch

R/functions-renamed.R#L18

Added line #L18 was not covered by tests

set_prevalence_tool(tool, n, as_proportion = FALSE)
set_distribution_tool(
tool,
distfun = distribute_tool_randomly(
prevalence = n,
as_proportion = TRUE

Check warning on line 24 in R/functions-renamed.R

View check run for this annotation

Codecov / codecov/patch

R/functions-renamed.R#L20-L24

Added lines #L20 - L24 were not covered by tests
)
)

add_tool(model, tool)

Check warning on line 28 in R/functions-renamed.R

View check run for this annotation

Codecov / codecov/patch

R/functions-renamed.R#L28

Added line #L28 was not covered by tests

}
Expand All @@ -28,7 +34,15 @@ add_tool_n <- function(model, tool, n) {
add_virus_n <- function(model, virus, n) {

.Deprecated(new = "add_virus")

Check warning on line 36 in R/functions-renamed.R

View check run for this annotation

Codecov / codecov/patch

R/functions-renamed.R#L36

Added line #L36 was not covered by tests
set_prevalence_virus(virus, n, as_proportion = FALSE)

set_distribution_virus(
virus = virus,
distfun = distribute_virus_randomly(
prevalence = n,
as_proportion = TRUE

Check warning on line 42 in R/functions-renamed.R

View check run for this annotation

Codecov / codecov/patch

R/functions-renamed.R#L38-L42

Added lines #L38 - L42 were not covered by tests
)
)

add_virus(model, virus)

Check warning on line 46 in R/functions-renamed.R

View check run for this annotation

Codecov / codecov/patch

R/functions-renamed.R#L46

Added line #L46 was not covered by tests

}
19 changes: 13 additions & 6 deletions R/tool.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
#'
#' # To declare a certain number of individuals with the tool
#' rm_tool(model_sirconn, 0) # Removing epitool from the model
#' set_prevalence_tool(epitool, 0.1, TRUE) # Setting prevalence to 0.1
#' # Setting prevalence to 0.1
#' set_distribution_tool(epitool, distribute_tool_randomly(0.1, TRUE))
#' add_tool(model_sirconn, epitool)
#' run(model_sirconn, ndays = 100, seed = 1912)
#'
Expand Down Expand Up @@ -152,8 +153,7 @@ get_name_tool <- function(tool) {

#' @export
#' @param tool An object of class `epiworld_tool`
#' @param proportion Deprecated. Either set the prevalence during the tool
#' initialization or use `set_prevalence_tool`.
#' @param proportion Deprecated.
#' @details
#' The `add_tool` function adds the specified tool to the model of class
#' [epiworld_model] with specified proportion.
Expand All @@ -164,10 +164,13 @@ add_tool <- function(model, tool, proportion) {

warning(
"The 'proportion' argument is deprecated. ",
"Use 'set_prevalence_tool' instead."
"Use 'set_distribution_tool' instead."

Check warning on line 167 in R/tool.R

View check run for this annotation

Codecov / codecov/patch

R/tool.R#L165-L167

Added lines #L165 - L167 were not covered by tests
)

set_prevalence_tool(tool, proportion, TRUE)
set_distribution_tool(
tool,
distribute_tool_randomly(proportion, TRUE)

Check warning on line 172 in R/tool.R

View check run for this annotation

Codecov / codecov/patch

R/tool.R#L170-L172

Added lines #L170 - L172 were not covered by tests
)

}

Expand Down Expand Up @@ -502,12 +505,13 @@ print.epiworld_agents_tools <- function(x, max_print = 10, ...) {
#' specified tool of class [epiworld_tool]. The distribution function can be
#' created using the functions [distribute_tool_randomly()] and
#' [distribute_tool_to_set()].
#' @param distfun An object of class `epiworld_tool_distfun`.
#' @rdname tool
set_distribution_tool <- function(tool, distfun) {

stopifnot_tool(tool)
stopifnot_tool_distfun(distfun)
invisible(set_distribution_tool_cpp(tool, distfun))
invisible(set_distribution_tool_cpp(tool = tool, distfun = distfun))

Check warning on line 514 in R/tool.R

View check run for this annotation

Codecov / codecov/patch

R/tool.R#L512-L514

Added lines #L512 - L514 were not covered by tests

}

Expand All @@ -516,6 +520,9 @@ set_distribution_tool <- function(tool, distfun) {
#' @details
#' The `distribute_tool_randomly` function creates a distribution function that
#' randomly assigns the tool to a proportion of the population.
#' @param as_proportion Logical scalar. If `TRUE`, `prevalence` is interpreted
#' as a proportion of the total number of agents in the model.
#' @param prevalence Numeric scalar. Prevalence of the tool.
#' @return
#' - The `distribute_tool_randomly` function returns a distribution function of
#' class `epiworld_tool_distfun`.
Expand Down
24 changes: 13 additions & 11 deletions R/virus.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#' mseirconn
#'
#' rm_virus(mseirconn, 0) # Removing the first virus from the model object
#' set_prevalence_virus(delta, 100, as_proportion = FALSE)
#' set_distribution_virus(delta, distribute_virus_randomly(100, as_proportion = FALSE))
#' add_virus(mseirconn, delta)
#'
#' # Setting parameters for the delta virus manually
Expand Down Expand Up @@ -154,8 +154,7 @@ get_name_virus <- function(virus) {
#' @rdname virus
#' @param model An object of class `epiworld_model`.
#' @param virus An object of class `epiworld_virus`
#' @param proportion Deprecated. Either set the prevalence during the virus
#' initialization or use `set_prevalence_virus`.
#' @param proportion Deprecated.
#' @returns
#' - The `add_virus` function does not return a value, instead it adds the
#' virus of choice to the model object of class [epiworld_model].
Expand All @@ -168,7 +167,10 @@ add_virus <- function(model, virus, proportion) {
"the next version."

Check warning on line 167 in R/virus.R

View check run for this annotation

Codecov / codecov/patch

R/virus.R#L165-L167

Added lines #L165 - L167 were not covered by tests
)

set_prevalence_virus(virus, proportion, as_proportion = TRUE)
set_distribution_virus(
virus=virus,
distfun=distribute_virus_randomly(proportion, as_proportion = TRUE)

Check warning on line 172 in R/virus.R

View check run for this annotation

Codecov / codecov/patch

R/virus.R#L170-L172

Added lines #L170 - L172 were not covered by tests
)

}

Expand Down Expand Up @@ -521,12 +523,12 @@ set_incubation_fun <- function(virus, model, vfun) {

#' @export
#' @rdname virus
#' @param dist_fun An object of class `epiworld_distribution_virus`.
set_distribution_virus <- function(virus, dist_fun) {
#' @param distfun An object of class `epiworld_distribution_virus`.
set_distribution_virus <- function(virus, distfun) {

stopifnot_virus(virus)
stopifnot_virus_distfun(dist_fun)
invisible(set_distribution_virus_cpp(virus, dist_fun))
stopifnot_virus_distfun(distfun)
invisible(set_distribution_virus_cpp(virus, distfun))

Check warning on line 531 in R/virus.R

View check run for this annotation

Codecov / codecov/patch

R/virus.R#L529-L531

Added lines #L529 - L531 were not covered by tests

}

Expand All @@ -552,20 +554,20 @@ distribute_virus_randomly <- function(
as.double(prevalence),
as.logical(as_proportion)

Check warning on line 555 in R/virus.R

View check run for this annotation

Codecov / codecov/patch

R/virus.R#L552-L555

Added lines #L552 - L555 were not covered by tests
),
class = "epiworld_distribution_virus"
class = "epiworld_virus_distfun"

Check warning on line 557 in R/virus.R

View check run for this annotation

Codecov / codecov/patch

R/virus.R#L557

Added line #L557 was not covered by tests
)

}

#' @export
#' @rdname virus
#' @param agents_id Integer vector. Indices of the agents that will receive the
#' @param agents_ids Integer vector. Indices of the agents that will receive the
#' virus.
distribute_virus_set <- function(agents_ids) {

structure(
distribute_virus_set_cpp(as.vector(agents_id)),
class = "epiworld_distribution_virus"
class = "epiworld_virus_distfun"

Check warning on line 570 in R/virus.R

View check run for this annotation

Codecov / codecov/patch

R/virus.R#L568-L570

Added lines #L568 - L570 were not covered by tests
)

}
6 changes: 3 additions & 3 deletions inst/tinytest/test-mixing.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ flu_model <- ModelSEIRMixing(

# Adding the entities
flu_model |>
add_entity_n(e1) |>
add_entity_n(e2) |>
add_entity_n(e3)
add_entity(e1) |>
add_entity(e2) |>
add_entity(e3)

run(flu_model, ndays = 100, seed = 1233)
summary(flu_model)
Expand Down
1 change: 0 additions & 1 deletion man/agents_smallworld.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/entities.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/epiworldR-deprecated.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/tool.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions man/virus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions playground/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*_files/
*_cache/

/.quarto/
Loading

0 comments on commit 97e074a

Please sign in to comment.