Reputation: 330
I am using kmeansFilter function from FlowCore to create a filter (class?) for downstream analysis.
I am having trouble passing a variable to the function:
#install flowCore via BiocManager::install("flowCore")
library(flowCore)
#Working example:
## Create the filter
kf <- kmeansFilter("FSC-H"=c("Pop1","Pop2","Pop3"), filterId="myKmFilter")
kf@parameters[[1]]
# unitytransform on parameter 'FSC-H'
#Desire:
channel <- "FSC-H"
kf <- kmeansFilter(channel=c("Pop1","Pop2","Pop3"), filterId="myKmFilter")
kf@parameters[[1]]
# unitytransform on parameter 'channel'
channel
not being passed. I have tried sym()
and other, but it seems I am missing something.
Any assistance is appreciated.
EDIT:
as @jay.sf pointed out int he comment, parameters are defined as list. so you can define the first parameter as a list. But list()
can pass a variable (example below); list()
in the function kmeansFilter
does not show this case.
tkf <- "test"
channel <- list(tkf=c("Pop1","Pop2","Pop3")) #tkf passed as "test"
kf <- kmeansFilter(channel, filterId="myKmFilter")
I think the workaround is clear, but it stood out as something if off, and I got curious a bit.
Upvotes: 0
Views: 65
Reputation: 76673
The solution is to follow the documentation and pass channel
as a named list. From help("kmeansFilter")
, section Arguments, my emphasis:
kmeansFilter are defined by a single flow parameter and an associated list of k population names. They can be given as a character vector via a named argument, or as a list with a single named argument. In both cases the name will be used as the flow parameter and the content of the list or of the argument will be used as population names, after coercing to character.
In the code below I use a list as the flow parameter.
channel <- list(`FSC-H` = c("Pop1","Pop2","Pop3"))
kf2 <- kmeansFilter(
channel,
filterId = "myKmFilter"
)
kf2@parameters[[1]]
#unitytransform on parameter 'FSC-H'
kf2
#k-means filter 'myKmFilter' in dimension FSC-H
#with 3 populations (Pop1,Pop2,Pop3)
Note that the flow parameter can also be defined with the name between single or double quotes. I have defined it between back ticks but this is not mandatory. The following also works.
channel <- list("FSC-H" = c("Pop1","Pop2","Pop3"))
If the name is chosen programmatically, then the workaround in the question or to set the name with names<-
or with setNames
are the best options.
Upvotes: 2