Error in `reticulate::use_virtualenv(virtualenv_python)`: Directory ~/.virtualenvs/r-bigergm is not a Python virtualenv

x <- sample(1:10, size = N, replace = TRUE)
y <- sample(1:10, size = N, replace = TRUE)
list_between_params <- c(-3.5, 0.5, 0.5)
formula <- g ~ edges + nodematch("x") + nodematch("y") + triangle
ergm_control = ergm::control.simulate.formula(MCMC.burnin = 1000000, MCMC.interval = 1000),
# Function that checks that the number of files in the directory is the expected number
do.call(file.remove, list(list.files(tempdir(), '*.rds', full.names = TRUE)))
test_that('Estimation with a disk cache stores data in the correct directory', {
# Use this directory for caching in disk
# There should be no cached files in the directory
# The estimation should have stored one RDS object in the cache directory.
# Running again the estimation on the same network should reuse the previously stored RDS object
# Perform estimation on the new network.
# The network has changed, so the previously cached RDS is not reused and a new cache file is generated.

'Estimation with a disk cache stores data in the correct directory'

Estimation with a disk cache stores data in the correct directory

get_dummy_net <- function(n_nodes, n_clusters, em_iters = 10, seed = 1234) {
hergm_formula <- g ~ edges + triangle + nodematch("x")
x = sample(1:2, size = n_nodes, replace = T),
block = sample(1:n_clusters, size = n_nodes, replace = T)
g <- network::network.initialize(n = n_nodes)
test_that("Returned GOF dataframe has the correct fields", {
for (stat_type in c("original", "simulated")) {
for (stat in c("network_stats", "degree_dist", "esp_dist")) {
test_that("GOF network stats have the right fields and terms", {
actual_terms[stringr::str_detect(actual_terms, "n_sim", negate = TRUE)] %>%
test_that("GOF degree stats have the right fields and terms", {
min(stat_type_df$degree_dist$share) >= 0 && max(stat_type_df$degree_dist$share) <= 1,
failure_message = "Some degree shares are out of bounds"
test_that("GOF esp stats have the right fields and terms", {
min(stat_type_df$esp_dist$esp) >= 0 && max(stat_type_df$esp_dist$esp) <= (g$gal$n^2),
failure_message = "Some esp counts are out of bounds."
test_that("GOF geodesic distance is returned when requested", {
# Some of the distances will be Inf, and that's ok (that's how ergm returns them).
(min(stat_type_df$geodesic_dist$pairs) >= 0) && (max(stat_type_df$geodesic_dist$pairs) <= (g$gal$n^2)),
failure_message = "Some geodesic distance pairs are out of bounds."
test_that("Return GOF statistics including only within-block connections", {
# check that the network stats belong to the within-block sub network only
edgelist <- network::as.edgelist(g) %>% as.data.frame
nodes_with_blocks <- data.frame(id = 1:length(network::network.vertex.names(g)), block=network::get.vertex.attribute(g, 'block'))
dplyr::left_join(nodes_with_blocks, by = c('src' = 'id')) %>%
dplyr::left_join(nodes_with_blocks, by = c('dst' = 'id'), suffix=c('.src', '.dst')) %>%
within_conns_from_gof <- (test_gof_res$original$network_stats %>% dplyr::filter(stat == 'edges'))[, 2]
test_that("Within-connections GOF can be started from the observed network", {
test_that("Full GOF can be started from the observed network", {
# If it starts from the observed network, the stats should not be zero