I have an object (Seurat object) an I need to get certain data out of it
> sc@misc[["colors"]][["seurat_clusters"]]
0 1 2 3 4 5 6 7
"#CC0C00FF" "#5C88DAFF" "#84BD00FF" "#FFCD00FF" "#7C878EFF" "#00B5E2FF" "#00AF66FF" "#CC0C00B2"
This data is needed as an vector but I don't know how to pull "#CC0C00FF" "#5C88DAFF" etc. out of it.
In order to hand this data to the next function, the result should look like this:
> vec
[1] "#CC0C00FF" "#5C88DAFF" "#84BD00FF"
Thanks in advance!
Solved it! I'm pretty disappointed by myself, because I didn't know this function existed:
> as.vector(sc@misc[["colors"]][["seurat_clusters"]])
[1] "#CC0C00FF" "#5C88DAFF" "#84BD00FF" "#FFCD00FF" "#7C878EFF" "#00B5E2FF" "#00AF66FF" "#CC0C00B2"
Just for your understanding,
as.vector
is almost certainly not needed: the result already is a vector. That vector has names (which are stripped byas.vector
) so it is displayed differently. But these names shouldn’t be a problem, so you don’t need to strip them. (I’m basing this on the output of your code … it’s possible that what’s returned is actually something different, but that’s unlikely).Something else, you can probably simplify the code by using name access instead of subsetting based on a value. That is, you can write
sc@misc$colors$seurat_clusters
instead of what you’ve written.@KonradRudolph I also thought these names shouln't be a problem. The doc says "Also accepts a Brewer color scale or vector of colors" and your example
is.vector(sc@misc$colors$seurat_clusters) [1] TRUE
. Nontheless the function only runs if I remove the names.