2

I am testing the capabilities to run my R script in QGIS. I am facing a basic question.

I am defining a dropdown menu with all the parameters for a specific variable:

##test1=group
##Sensor?=selection S1;S2;S1 AND S2

enter image description here

Then I use this basic code to test if I can use the selection of the user within an if statement

if (S1){
print("It is working")
}

My script is not working and is reporting the following error. Any idea how this type of variables can be used in a if statement. Shoud I use a reguluar boolean variable. If so, how should it be implemented?

Sensor?=0
Error: unexpected '=' in "Sensor?="
Execution halted
Converting outputs
Loading resulting layers
Algorithm [Unnamed algorithm] finished
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Feb 26, 2019 at 10:10

1 Answer 1

3

Just found the solution,

##test1=group
##Sensor=selection S1;S2;S1 AND S2
if (Sensor == "S1"){
print("It is working")
}

I think there is little information or non-unified place to find documentation about the implementation of R scripts in QGIS. If you find a good guide, please feel free to add it on the comments.

--- EDIT ---

Based on another post (Using if statement in R script within QGIS)

##test1=group
##Sensor=selection S1;S2;S1 AND S2
if (Sensor == 0){
print("It is working")
}

works as well taking into account the python indexing rule

answered Feb 26, 2019 at 10:17
3
  • 2
    Actually posting an answer to your own question so others can use it. Hero. Commented Feb 26, 2019 at 10:18
  • 2
    @TeddyTedTed, I think it happens to me as well. Sometimes the solution is much simpler than you expected. But when you are lost you are normally trying to implement any possible approaches to achieve the result that you are striving for. And then at some point, you see that miserable answer hidden in your "Learn by falling, falling, ... , falling, trying, and achieving" method. And IMHO it is always better when you find solution/answering your own question by yourself. Commented Feb 26, 2019 at 11:52
  • 3
    @Taras I definitely agree, very satisfying to finally figure something out as well. My previous comment was meant as praise for GCGM posting an answer to their own question, sorry for any confusion. Commented Feb 26, 2019 at 12:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.