I am creating an R script in QGIS and I am facing an issue with an if statement
. First, I declare the input from the user
##Which_S2_bands_do_you_want_to_use=selection 2 3 4 5 6 7 8 11 12;2 3 4 8 11 12
Later I use it in the following condition:
if (Which_S2_bands_do_you_want_to_use == "2 3 4 5 6 7 8 11 12") {
bands<-c("B((0[2348]_10m)|(((0[567])|(1[12])|(8A))_20m)).jp2$")}
And use it in the following code:
S2<-list.files(S2, recursive = TRUE, full.names = TRUE, pattern=bands)
When I run it, I get the following error:
Error in list.files(S2, recursive = TRUE, full.names = TRUE, pattern = bands) :
object 'bands' not found
Execution halted
It seems the if statment
is not been run. Any idea what could be the reason?
Maybe another approach to use the input from the user as a condition to change a variable in the script?
selection
parameter type returns an integer corresponding to the position of the selection. See this answer: gis.stackexchange.com/a/220078/70980. So if the user selects the first option it returns 0, the second option returns 1, and so on. You can verify this by adding a print statement with your parameter variable at the beginning of your script.