Save a type environment result from R in Excel

Hello! Does anyone know how to export the results in Excel in case I have data of type environment? I have done a simulation and I was to export the results.

Thank you

an environment is an assortment of variables.
You'll have to corral the contents into a data.frame(s).
How easy/hard this will be will depend on your knowledge of what you've been doing and whats gone into the environment in question...

You could have a look at the function simmer:::print.simmer to see which items to 'corral' :

function (x, ...) 
    cat(paste0("simmer environment: ", x$name, " | now: ", 
        now(x), " | next: ", peek(x), "\n", "{ Monitor: ", 
        x$mon$name, " }\n"))
    for (name in names(x$mon$handlers)) cat(paste0("  { ", 
        name, ": ", x$mon$handlers[[name]], " }\n"))
    for (name in names(x$resources)) cat(paste0("{ Resource: ", 
        name, " | monitored: ", x$resources[[name]][["mon"]], 
        " | server status: ", get_server_count(x, name), 
        "(", get_capacity(x, name), ")", " | queue status: ", 
        get_queue_count(x, name), "(", get_queue_size(x, 
            name), ") }\n"))
    for (name in names(x$sources)) cat(paste0("{ Source: ", 
        name, " | monitored: ", x$sources[[name]][["mon"]], 
        " | n_generated: ", get_n_generated(x, name), " }\n"))
    for (name in names(x$globals)) {
        value <- x$globals[[name]]
        is_schedule <- inherits(value, "schedule")
        if (is_schedule) 
            value <- value$schedule$init
        cat(paste0("{ Global: ", name, " | schedule: ", 
            is_schedule, " | initial value: ", value, " }\n"))
<bytecode: 0x000001d34a12a2a8>
<environment: namespace:simmer>


if you are talking about the output of one of the get_mon_* functions you can always use the write.csv function:

zz = terminal %>%
write.csv(zz,'zz.csv',row.names = F)

I think you are trying to write the wrong object (?)
Building on your example of a few days ago I have no problems writing data with

terminal <-
simmer("terminal") %>%
add_global("berth_size",0) %>%
add_resource("berth",5) %>%
      deepsea, function() { c(0, rgamma(79, 1.47,0.23))},mon=2) %>%  
      barge, function() { c(0, rgamma(609,1.14,0.04))})       

terminal %>%
run(until = 500)

xx = terminal %>%
    get_mon_arrivals() %>%
    transform(waiting_time = end_time - start_time - activity_time)

write.csv(xx,'xx.csv',row.names = F)

Is this not working for you ?

I did it again and now it worked thank you very much for your help! Really appreciated it!

You are very welcome and thanks for pointing me to the simmer package.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Thank you very much!

Thank you! My environment so far contains data in 7 columns which have a length of 500 rows. I will check how to corral them into a data frame

Indeed, I am taking about the output of get_mon_arrivals but when I used the write.csv function the following error occured: Error in[[i]], optional = TRUE) :
cannot coerce class ‘"simmer"’ to a data.frame