loading...

Create and manage a temporary environment SciViews:TempEnv low enough on the search path so that all loaded packages (except base) could easily access objects there.

temp_env()

add_items(x, y, use.names = TRUE, replace = TRUE)

add_temp(x, item, value, use.names = TRUE, replace = TRUE)

assign_temp(x, value, replace.existing = TRUE)

change_temp(x, item, value, replace.existing = TRUE)

exists_temp(x, mode = "any")

get_temp(x, default = NULL, mode = "any", item = NULL)

delete_temp(x)

rm_temp(x)

TempEnv()

addItems(x, y, use.names = TRUE, replace = TRUE)

addTemp(x, item, value, use.names = TRUE, replace = TRUE)

assignTemp(x, value, replace.existing = TRUE)

changeTemp(x, item, value, replace.existing = TRUE)

existsTemp(x, mode = "any")

getTemp(x, default = NULL, mode = "any", item = NULL)

rmTemp(x)

Arguments

x

The vector to add items to for add_items() or any object. for delete_temp(), it is the name of the variable (character string), or a vector of characters with the name of all variables to remove from SciViews:TempEnv.

y

The vector of which we want to inject missing items in 'x'.

use.names

Use names of items to determine which one is unique, otherwise, the selection is done on the items themselves.

replace

Do we replace existing items in 'x'?

item

The item to add data to in the list.

value

The value to add in the item, it must be a named vector and element matching is done according to name of items.

replace.existing

Do we replace an existing variable?

mode

The mode of the seek variable

default

The default value to return, in case the variable or the item does not exist.

Value

The temporary environment for temp-env(), the value assigned, added or changed for assign_temp(), add_temp(), change_temp(), or get_temp(). TRUE or FALSE for exists_temp(), delete_temp() or rm_temp().

Details

The temporary environment is attached to the search path for easier access to its objects.

Examples

ls(temp_env())
#> [1] "last.warning"

# I have a vector v1 with this:
v1 <- c(a = "some v1 text", b = "another v1 text")
# I want to add items whose name is missing in v1 from v2
v2 <- c(a = "v2 text", c = "the missign item")
add_items(v1, v2, replace = FALSE)
#>                  a                  b                  c 
#>     "some v1 text"  "another v1 text" "the missign item" 
# Not the same as
add_items(v1, v2, replace = TRUE)
#>                  a                  c                  b 
#>          "v2 text" "the missign item"  "another v1 text" 
# This yield different result (names not used and lost!)
add_items(v1, v2, use.names = FALSE)
#> [1] "another v1 text"  "some v1 text"     "the missign item" "v2 text"         

add_temp("tst", "item1", c(a = 1, b = 2))
# Retrieve this variable
get_temp("tst")
#> $item1
#> a b 
#> 1 2 
#> 
# Add to item1 in this list without replacement
add_temp("tst", "item1", c(a = 45, c = 3), replace = FALSE)
get_temp("tst")
#> $item1
#> a b c 
#> 1 2 3 
#> 
# Same but with replacement of existing items
add_temp("tst", "item1", c(a = 45, c = 3), replace = TRUE)
get_temp("tst")
#> $item1
#>  a  c  b 
#> 45  3  2 
#> 
# Delete the whole variable
delete_temp("tst")

assign_temp("test", 1:10)
# Retrieve this variable
get_temp("test")
#>  [1]  1  2  3  4  5  6  7  8  9 10

change_temp("tst", "item1", 1:10)
# Retrieve this variable
get_temp("tst")
#> $item1
#>  [1]  1  2  3  4  5  6  7  8  9 10
#> 
# Create another item in the list
change_temp("tst", "item2", TRUE)
get_temp("tst")
#> $item1
#>  [1]  1  2  3  4  5  6  7  8  9 10
#> 
#> $item2
#> [1] TRUE
#> 
# Change it
change_temp("tst", "item2", FALSE)
get_temp("tst")
#> $item1
#>  [1]  1  2  3  4  5  6  7  8  9 10
#> 
#> $item2
#> [1] FALSE
#> 
# Delete it (= assign NULL to the item)
change_temp("tst", "item2", NULL)
get_temp("tst")
#> $item1
#>  [1]  1  2  3  4  5  6  7  8  9 10
#> 
# Delete the whole variable
delete_temp("tst")

assign_temp("test", 1:10)
# Check if this variable exists
exists_temp("test")
#> [1] TRUE
# Remove it
delete_temp("test")
# Does it still exists?
exists_temp("test")
#> [1] FALSE