How can you test if a variable is empty or not defined in a qmake .pro file? I want to
be able to set up a default value if the variable is not defined.
I tried
eval("VARIABLE" = ""){
VARIABLE = test
}
eval("VARIABLE" = ""){
message(variable is empty)
}
but I still get the message "variable is empty".
there is already the function isEmpty I didn't spot:
isEmpty(VARIABLE){
VARIABLE = test
}
isEmpty(VARIABLE ){
message(variable is empty)
}
I don't understand why eval didnt work thought...
Like your own answer says, isEmpty(VARIABLE) does what you want:
isEmpty(VARIABLE) {
...
}
The qmake language has no equivalent of an equals operator (==), but you can compare things like this:
equals(VARIABLE, foo) {
...
}
You can also check if a variable contains a substring, using a regular expression:
contains(VARIABLE, .*foo.*) {
...
}
The reason why eval() didn't work, is that it executes the statement within it and returns true if the statement succeeded.
So by doing this:
eval(VARIABLE = "") {
...
}
...you are actually assigning "" to VARIABLE, making the variable empty and entering the block.
More about test functions: http://qt-project.org/doc/qt-5/qmake-test-function-reference.html
Related
Greetings I am getting an error of
Error in if (nrow(pair) == 0) { :argument is of length zero
I have checked the other answers but do not seem to work on a variable like mine. Please check code below, please assist if you can.
pair<-NULL
if(exists("p.doa.ym")) pair <- rbind(pair, p.doa.ym[,1:2])
if(exists("p.doa.yd")) pair <- rbind(pair, p.doa.yd[,1:2])
if(nrow(pair) == 0) {
print("THERE ARE NO MATCHES FOR TODAY. STOP HERE")
quit()
}
Since you set pair=NULL and then it might happen that pair stays null if those two if statements are not true, you either need to check if pair is null first, or you could set pair to an empty data frame, or something else.
One option:
if (!is.null(pair)) {
if (nrow(pair)==0) {
# your code
}
}
Another option:
pair=data.frame()
# your code
I have create a small script that passes a vector through a loop. In this loop I am using an if else statement to check if folder exists and if not to create the folder. However, I am getting error: Error in file.exists(i) : invalid 'file' argument. This has to due with file.exist(). I dont understand why this isnt ok. I check the man using help. Seems like this should be working.
folders<- c("RawData", "Output", "BCV", "DEplots", "DEtables", "PathwayOuts", "VolcanoPLots")
for(i in 1:length(folders)){
if (file.exists(i)){
cat(paste0(i, "already exists"))
} else {
cat(paste0(i, "does not exists"))
dir.create(i)
}
}
You are looping over an index (that is, 1:length(folders) is just the vector 1:7, not the values of the folders vector itself. The easiest solution is to loop over the vector itself:
for (i in folders) {
Or, if you still want to loop over the index:
for (i in 1:length(folders)) {
if (file.exists(folders[i])){
cat(paste0(folders[i], "already exists"))
}
else {
cat(paste0(folders[i], "does not exists"))
dir.create(folders[i])
}
}
A quick tip: if you are debugging a for-loop, the place to start is to add print(i) at the start of the loop. You would have immediately seen the problem: i was an integer, not the first value of the vector.
I have a delta with some methods in it.
I want to create a schema extract that contains only the methods in the delta in an automated way so that I don't have to create one by hand or using the hateful selection tree in the Jade IDE.
The jadeworld documentation suggests I might be able to do it:
https://www.jadeworld.com/docs/jade-70/content/resources/userguide/chapter_10_-_extracting_and_loading_schemas/extracting_schemas_as_a_non-gui_client_application.htm
When I try, no extract files are created.
This is the command I am running:
jadclient path=E:\Jade63\System\ schema=JadeSchema ini=C:\Jade63\bin\jade.ini app=JadeBatchExtract endJade File d:\temp\delta.scm d:\temp\delta.ddb d:\temp\param.unl delta=TFS3274
Any help would be appreciated.
For 'File' extracts, you need to specify which schema to extract. This is the fourth parameter, after the UNL file, before adding the delta argument. I've added this to the example below, assuming 'Delta' is the schema name.
jadclient path=E:\Jade63\System\ schema=JadeSchema ini=C:\Jade63\bin\jade.ini app=JadeBatchExtract endJade File d:\temp\delta.scm d:\temp\delta.ddb d:\temp\param.unl Delta delta=TFS3274
Unfortunately, I'm not sure if this will extract just the methods that are in the specified delta. Rather, I believe everything specified by the UNL file will be extracted, but where any methods are checked out to a delta, the version in the specified delta will be extracted.
You'll need to experiment to confirm, but in my experience, patches are more suitable for performing extracts without needing to specify what's changed.
Kevin's has answered the question I asked, I'm just adding this bit here for anyone else who happens this way. I was trying to automate creating a UNL file from a delta. The following perl script will generate a UNL file from a schema extract file. So you can create a schema extract from a delta in the IDE, then run this script on it to create a UNL, which you can then use for creating subsequent extracts.
#!/usr/bin/perl
$state="init";
$class="";
$method="";
#result=();
while(<>)
{
if($state eq "init")
{
if(m/typeDefinitions/)
{
$state="inTypes";
}
}
elsif($state eq "inTypes")
{
if(m/[^(]+\(\r/)
{
$state="inClass";
($class=$_) =~ s/\s*(\S+).*\(/$1/;
$class =~ s/[\r\n]//g;
}
elsif(m/inverseDefinitions/)
{
$state="done";
}
}
elsif($state eq "inClass")
{
if(m/jadeMethodDefinitions/)
{
$state="inMethod";
}
elsif(m/^\s*\)\r/)
{
$state="inTypes";
}
}
elsif($state eq "inMethod")
{
if(m/[^(]+[(]/)
{
($method=$_) =~ s/\s*(\S+)\(.*/$1/;
$method =~ s/[\r\n]//g;
$state="inClass";
push #result, "Method $class $method\n";
}
}
}
#result = sort #result;
print #result;
print "\n";
This is an extension of the previous post In R, how to get an object's name after it is sent to a function? and its also popular duplicate How to convert variable (object) name into String [duplicate]
The idea is that you have a list of parameter values, e.g.
parameters <- c(parameter1,parameter2,...)
and you want to write to a file the parameter name (the variable) and value, e.g
parameter1: 500
parameter2: 1.2
...
In the previous posts we saw this function:
getVariablesName <- function(variable) {
substitutedVariable <- substitute(variable);
if (length(substitutedVariable) == 1) {
deparse(substitutedVariable)
} else {
sub("\\(.", "", substitutedVariable[2])
}
}
which is capable of recalling the passed variable's "name"
getVariablesName(foo)
'foo'
but when a variable is passed twice, we loss this information, e.g.
logThis <- function(thingsToLog, inThisFile) {
for (thing in thingsToLog) {
write(paste(getVariablesName(thing),":\t",thing),
file = inThisFile,
append = TRUE)
}
}
the idea being to pass logThis(c(parameter1,parameter2,...), "/home/file.txt")
So how can we retain the variables' "names" as they get encapsulated in a vector, passed to the function logThis and then looped through?
I use latest Robot Framework.
I need to assign a value to my variable depending on value of an argument. That's how it would be in JavaScript:
ITEM_SELECTOR = RECENT_ITEM_SELECTOR + (
position === 'last' ? ':last-child' : ':nth-child' + '(' + position + ')'
)
This is how I try to write it in Robot Framework:
${ITEM_SELECTOR} = Run Keyword If ${position} == 'last' ${RECENT_ITEM_SELECTOR}:last-child
... ELSE ${RECENT_ITEM_SELECTOR}:nth-child(${position})
but this way ${RECENT_ITEM_SELECTOR}:nth-child(${position}) is considered a keyword, not assigned to ITEM_SELECTOR.
Then I try to preprend it with No Operation, but then my return value is considered its argument and I get Keyword 'BuiltIn.No Operation' expected 0 arguments, got 1.
How can I write it?
Since you are calling run keyword if, you have to give it a keyword to run. You can use set variable to make your code work:
${ITEM_SELECTOR} = Run Keyword If ${position} == 'last'
... Set variable ${RECENT_ITEM_SELECTOR}:last-child
... ELSE
... Set variable ${RECENT_ITEM_SELECTOR}:nth-child(${position})
However, you can also use set variable if for a slightly more compact and readable solution:
${ITEM_SELECTOR} = Set variable if ${position} == 'last'
... ${RECENT_ITEM_SELECTOR}:last-child
... ${RECENT_ITEM_SELECTOR}:nth-child(${position})