I need to schedule a job. I want it to run if, and only if some global variable (let's say RUNNING_ID) is not equal to 0.
Is that possible ?
If it is, waht is the Condition syntax for the job description ?
I tried RUNNING_ID!=0, and got this error :
CAUAJM_E_10037 CONDITION ERROR: Illegal Key Word: RUNNING_ID!=0
CAUAJM_E_10281 ERROR for Job: CVAT-TENSEN2CUX-launch_decision < Error in Starting Conditions. >
Ok, figured it out :
The syntax :
VALUE(global_variable_name) operator value
with operator being one of these : =, !=, <, >, <= and >=
Related
I am trying to test against multiple environments with a single test case using the passing in of a variable from the command line. Using the following command line:
robot --variable TESTENV:prod advertisingdisclosure_Page.robot
I need to test the value of TESTENV and depending on the value passed in set a different variable, specifically a URL, to the appropriate value. With the following code in the first keyword section of the test case I get an error:
IF ${TESTENV} == "uat"
$(MAIN_URL)= Set Variable ${env_data['uat_url']}
ELSE IF ${TESTENV} == "dev"
${MAIN_URL}= Set Variable ${env_data['dev_url']}
ELSE IF ${TESTENV} == "prod"
${MAIN_URL}= Set Variable ${env_data["prod_url"]}
ELSE
Fail "No URL specified"
END
I get the following error:
Evaluating expression 'prod' failed: NameError: name 'prod' is not defined nor importable as module
The examples I have found show how to use the Global Variable directly, but not how to evaluate it for a specific value.
Help.
Jeff
You need to put quotes around the variable name - otherwise the framework just puts its value in, and passes that expression to python.
Thus it becomes prod == '"uat", and py rightfully complains there is no defined variable prod.
The fix is simple - just surround the usage in quotes, and after substitution this will become a string comparison:
"${TESTENV}" == "uat"
Alternatively you can use another syntax - no curly brackets, which tells RF to use/pass the variable itself, not its value, and then it will be a defined one for python:
$TESTENV == "uat"
Why is the following Robot statement complaining about 'Convert To Integer' keyword is invalid syntax? Thanks
Run Keyword If Convert To Integer ${packets_2} <= Convert To Integer ${packets_1}
... FAIL ${\n}[FAILED] Packets 2 not greater than packets 1.
... ${\n}packets_time1: ${packets_1} ${\n}packets_time2: ${packets_2}
You cannot call a keywords as the condition for Run Keyword If. The first argument is expected to be a python expression. Since you're trying to do a comparison of an integer, you can do that directly in the expression like so:
Run keyword if int('${packets_2}') <= int('${packets_1})
... FAIL \n[FAILED] Packets 2 not greater than packets 1
The other problem is that you are supplying two other arguments: ${\n}packets_time1: ${packets_1} and ${\n}packets_time2: ${packets_2}. It's not clear what you think those are for. I'm guessing you want them as part of the error message. If that's the case, it will have to be all on one line or else robot will think they are extra arguments to the FAIL keyword.
Run keyword if int('${packets_2}') <= int('${packets_1})
... FAIL \n[FAILED] Packets 2 not greater than packets 1\n$packets_time1: ${packets_1}\npackets_time2: ${packets_2}
I am executing following code in R using "IF" and the condition executed (I was expecting, it will give error message),
if("TRUE") print("ok")
can some one help me in understanding the logic behind the code execution?
My understanding is that "if statement" will execute when the conditional expression is true.
In the above code, I have given character as input, but the if condition is executed, which surprise me.
R converts the argument of if statement if it is interpretable as logical. In this case "TRUE" is interpretable as logical. Please see that as.logical("TRUE") returns TRUE. However, if("HELLO") print("ok") would not work and you will get the error:
Error in if ("HELLO") print("ok") :
argument is not interpretable as logical
You just need to fix the error in your syntax. Try this:
if (TRUE){
print("ok")
}
In Hadley Wickham's Advanced R, I'm having some trouble understanding one of the lazy evaluation examples.
Copied from the book, chapter on functions:
Laziness is useful in if statements — the second statement below will be >evaluated only if the first is true. If it wasn’t, the statement would return >an error because NULL > 0 is a logical vector of length 0 and not a valid input >to if.
x <- NULL
if (!is.null(x) && x > 0) {
}
As I understand the example, if R was not using lazy evaluation, the !is.null() and > 0 functions would be evaluated simultaneously, throwing an error since NULL is not a permissible argument to the ">" function. Is this correct? Is it thus generally advisable to include !is.null() in R statements when we expect that a variable could be NULL?
This is just the way the && operator works. It's called short-circuiting and is separate from lazy evaluation.
Lazy evaluation refers to the way function arguments are evaluated. In particular arguments are only evaluated when (if) they are actually used in the function. For example, consider the following function
f <- function(a, b) NULL
that does nothing and returns NULL. The arguments a and b are never evaluated because they are unused. They don't appear in the body of f, so you can call f with any expressions you want (as long as it's syntactically correct) as arguments because the expressions won't be evaluated. E.g.
> f(1, 2)
NULL
> f(43$foo, unboundvariableblablabla)
NULL
Without lazy evaluation the arguments are evaluated first and then passed to the function, so the call above would fail because if you try to evaluate 43$foo you'll get an error
> 43$foo
Error in 43$foo : $ operator is invalid for atomic vectors
I am using the function system.time() and I have discovered something which surprises me. I often use the allocation symbol “=” instead of “<-”. I am aware most R users use “<-” but I consider “=” clearer in my codes. Thus, I used “=” to allocate a value in a function system.line() and the following error message appeared : Error: unexpected '=' in "system.time(a[,1] ="
Here is the code :
a = matrix(1, nrow = 10000)
require(stats)
system.time(a[,1] = a[,1]*2) #this line doesn't work
#Error: unexpected '=' in "system.time(a[,1] ="
system.time(a[,1] = a[,1]*2) #this line works
system.time(for(i in 1:100){a[,1] = a[,1]*i}) #this line works!!!!
I found : Is there a technical difference between "=" and "<-" which explains that I can’t use “=” in a function to allocate since it is the symbol to assign argument in a function. But I have been surprised to see that it can work sometimes (see following code).
Does anyone know why it works here? (also why it doesn't work in the first case since I guess, a[,1] is not a parameter of the function system.time()...)
Thank you very much.
Edwin.
Wrap your code in { ... } braces and it will work:
system.time({a[,1] = a[,1]*2})
user system elapsed
0 0 0
From ?"<-"
The operators <- and = assign into the environment in which they are
evaluated. The operator <- can be used anywhere, whereas the operator
= is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a
braced list of expressions.
In system.time(a[,1] = a[,1]*2) the equals sign does not mean assignment, it is interpreted as an attempt to bind a "named argument"; but system.time does not have an argument of that name.
In system.time(for(i in 1:100){a[,1] = a[,1]*i}) the equals sign really is doing an assignment; and that works fine.
If you wrote system.time(a[,1] <- a[,1]*2) the <- can only mean assignment, not argument binding, and it works!
But beware! If you wrote system.time(a[,1] < - a[,1]*2), it also "works" but probably doesn't do what you meant!