-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
The group
argument is used to check whether a group with the same name already exists.
If so, the variable will be added to that group:
library("rjd3toolkit")
library("rjd3workspace")
tmp_path <- tempdir()
vars <- list(reg1 = list(x1 = AirPassengers))
my_context <- modelling_context(variables = vars)
my_ws <- jws_new(modelling_context = my_context)
add_variables(
jws = my_ws,
group = "reg1",
y = mdeaths,
name = "DeathMale"
)
save_workspace(my_ws, file.path(tmp_path, "tmp4.xml"), replace = TRUE)
If not, then a new group is created but with the name of the argument name
(not group) :
my_ws <- jws_new()
add_variables(
jws = my_ws,
group = "reg1",
y = mdeaths,
name = "DeathMale"
)
add_variables(
jws = my_ws,
group = "reg1",
y = fdeaths,
name = "DeathFemale"
)
add_variables(
jws = my_ws,
group = "DeathMale",
y = ldeaths,
name = "TotDeath"
)
save_workspace(my_ws, file.path(tmp_path, "tmp5.xml"), replace = TRUE)
readLines(file.path(tmp_path, "tmp5.xml")) |> cat(sep ="\n")
#> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
#> <ns2:demetraGenericWorkspace xmlns="ec/tss.core" xmlns:ns2="ec/tss.demetra" name="tmp5">
#> <ns2:items>
#> <ns2:item readOnly="false">
#> <ns2:family>Utilities@Variables</ns2:family>
#> <ns2:name>DeathMale</ns2:name>
#> <ns2:file>Vars-1</ns2:file>
#> </ns2:item>
#> <ns2:item readOnly="false">
#> <ns2:family>Utilities@Variables</ns2:family>
#> <ns2:name>DeathFemale</ns2:name>
#> <ns2:file>Vars-2</ns2:file>
#> </ns2:item>
#> </ns2:items>
#> </ns2:demetraGenericWorkspace>
read_variables(normalizePath(file.path(tmp_path, "tmp5/Variables/Vars-1.xml"))) |> str()
#> List of 2
#> $ DeathMale: Time-Series [1:72] from 1974 to 1980: 2134 1863 1877 1877 1492 ...
#> ..- attr(*, "name")= chr ""
#> $ TotDeath : Time-Series [1:72] from 1974 to 1980: 3035 2552 2704 2554 2014 ...
#> ..- attr(*, "name")= chr ""
read_variables(normalizePath(file.path(tmp_path, "tmp5/Variables/Vars-2.xml"))) |> str()
#> List of 1
#> $ DeathFemale: Time-Series [1:72] from 1974 to 1980: 901 689 827 677 522 406 441 393 387 582 ...
#> ..- attr(*, "name")= chr ""
Created on 2025-06-03 with reprex v2.1.1
Metadata
Metadata
Assignees
Labels
No labels