Open timmocking opened 8 months ago
There is maybe a better solution... @mikejiang ?
library(flowCore)
#> Warning: package 'flowCore' was built under R version 4.3.2
transforms <- list()
for (i in 1:8){
transforms[[LETTERS[i]]] <- logicleTransform(w = i)
}
# Print the width of "A" (should be 1)
environment(transforms$A@.Data)$w # output: [1] 8
#> [1] 8
environment(transforms$H@.Data)$w # output: [1] 8
#> [1] 8
# each transform/function has its own environment
sapply(transforms, environment)
#> $A
#> <environment: 0x000001f0342bb308>
#>
#> $B
#> <environment: 0x000001f0341d58f8>
#>
#> $C
#> <environment: 0x000001f0341cac30>
#>
#> $D
#> <environment: 0x000001f0340f9820>
#>
#> $E
#> <environment: 0x000001f033db1740>
#>
#> $F
#> <environment: 0x000001f033c91230>
#>
#> $G
#> <environment: 0x000001f033c62d48>
#>
#> $H
#> <environment: 0x000001f0336e89a0>
#
# so we can assign a value in each environment and check
for (i in 1:8) {
assign("w", i, envir = environment(transforms[[i]]))
}
for (i in 1:8) {
print(get("w", envir = environment(transforms[[i]])))
}
#> [1] 1
#> [1] 2
#> [1] 3
#> [1] 4
#> [1] 5
#> [1] 6
#> [1] 7
#> [1] 8
environment(transforms$A@.Data)$w
#> [1] 1
environment(transforms$H@.Data)$w
#> [1] 8
Created on 2024-02-05 with reprex v2.1.0
I want to create a transformList object by supplying a custom "w" parameter for every channel in a loop. However, when I create a list of transformations, the w-parameter is retro-actively modified for earlier items in the list.
For some reason, this can be prevented by calling summary() on the list if flowCore is loaded. However, the list becomes a closure type if flowCore is not loaded...
Is this the expected behavior?