what if you add g_marker <- 0 before the for loop to initialize the array?
https://www.datacamp.com/community/tutorials/tutorial-on-loops-in-r
could you try this command to see what is the output? I assume it's of type string.
a <- FindConservedMarkers(immune.combined, ident.1 = 0,
grouping.var = "stim", verbose = FALSE)
class(a)
Also you can try with a simpler code to see if your loop and your array work as expected, for example these scripts works for me
Numeric array:
g_marker <- 0
for (i in 0:4) { g_marker[i] <- i }
g_marker
> g_marker
[1] 1 2 3 4
String array:
# initialize the array with ""
g_marker <- ""
for (i in 0:4) { g_marker[i] <- sprintf("Gene %d",i) }
g_marker
> g_marker
[1] "Gene 1" "Gene 2" "Gene 3" "Gene 4"