How to get the expression used in an Assign activity - workflow-foundation-4

In the line below, "ThenActivity" is an Assign activity nested inside the Then part of an If activity. Im trying to get at the expression, but this snippet isnt working.
((Assign)ThenActivity).To.Expression.ToString();
This returns "1.13: CSharpReference"
When it should read R = 44.5M, which is the expression text, how do I get at it?

The statement should read something like this
((CSharpValue)(((Assign)ThenActivity).Value.Expression)).ExpressionText
Note: You need to get the assignment, then its expression, cast that as a CSharpValue, then finally you can get the ExpressionText.

Related

Cypress Reading values from a cell in a tab

When i try to read values from a single cell in a tab using cypress it returns {specwindow: , chainerid: ch-https://app.trahop.com-218} instead of returning values inside the cell.
This is the line of code which returns the meesage above:
cy.log(cy.get("tr:nth-child(1) td:nth-child(1)")) .Im sorry if this is a stupid question but i cant find any way to read the values inside the cell.
cy.get() does not yield a text variable, but instead yields a Cypress-wrapped DOM element. In order to see the value, you'll need to include it in a chained Cypress command, or yield it into a .then() (or similar) Cypress statement.
cy.get('tr:nth-child(1) td:nth-child(1)')
.should('have.text', 'foo');
cy.get('tr:nth-child(1) td:nth-child(1)')
.then(($el) => {
cy.log($el.text());
});

When does pressing the Enter (Return) key matter when creating a regex matching expression?

I want to search for multiple codes appearing in a cell. There are so many codes that I'd like to write parts of the code in succeeding lines. For example, let's say I am looking for "^a11","^b12", "^c67$" or "^d13[[:blank:]]". I am using:
^a11|^b12|^c67$|^d13[[:blank:]]
This seems to work. Now, I tried:
^a11|^b12|
^c67$|^d13[[:blank:]]
That also seemed to work. However when I tried:
^a11|^b12|^c67$|
^d13[[:blank:]]
It did not count the last one.
Note that my code is wrapped into a function. So the above is an argument that I feed the function. I'm thinking that's the problem, but I still don't know why one truncation works while the other does not.
I realized the answer today. The problem is that since I am feeding the regex argument, it will count the next line in the succeeding code.
Thus, the code below was only "working" because ^c67$ is empty.
^a11|^b12|
^c67$|^d13[[:blank:]]
And the code below was not working because ^d13 is not empty but also this setup looks for (next line)^d13[[:blank:]] instead of just ^d13[[:blank:]]
^a11|^b12|^c67$|
^d13[[:blank:]]
So an inelegant fix is:
^a11|^b12|^c67$|
^nothinghere|^d13[[:blank:]]
This inserts a burner code that is empty which is affected by the line break.

code executes outside function, but not inside it

my problem is, that some code gets executed outside a function, but not in it. In my example, the content of certain cells should be transferred from the input table to the output table. In case of removal or adding of rows/cols I don't access the cells by their index (e.g input[3,4]), but by application of a condition (e.g. input[(which(input$code=="A1")),(which(colnames(input)=="kg"))].
so here's a minimized version of my data:
input<-data.frame(animal=c("cat","dog","mouse","deer","lion"),
m=c(0.5,1,0.1,1.5,3),
kg=c(5,20,0.2,50,100),
code=c("A4","A5","A3","A1","A2"))
output<-data.frame(code=c("A1","A2","A3","A4","A5"),
kg=numeric(5))
execution outside the function, that works (the content of a cell of the input table should be copied to a suitable one in the output table):
row_out<-which(output$code=="A1")
col_out<-which(colnames(output)=="kg")
row_in<-which(input$code=="A1")
col_in<-which(colnames(input)=="kg")
output[row_out,col_out]<-input[row_in,col_in]
and the function, that contains the same code, which worked outside, except for the substitution of the quoted code expression for a function argument (codeexpression):
fun_transfer<-function(codeexpression){
row_out<-which(output$code==codeexpression)
col_out<-which(colnames(output)=="kg")
row_in<-which(input$code==codeexpression)
col_in<-which(colnames(input)=="kg")
output[row_out,col_out]<-input[row_in,col_in]
}
Problem: now the execution of
fun_transfer("A4")
does not lead to an error, nor to a result in the output table.
Why doesn't this function work or rather what does it do? Is there a problem with quotation marks?
any help would be appreciated
thanks,
Michel
In the best case, data enters a function as argument and leaves it as a return value.
Outside of a function
output[row_out,col_out] <- input[row_in,col_in]
changes the existing data.frame. You can (or better: should) not change some variable outside the function from within the function.
Just end your function with a return statement to return the changed dataframe to the caller
Edit
It appears as if what you try to write is a lesser version of merge. If the following answers your question it will probably be more concise, faster and more idiomatic:
input<-data.frame(animal=c("cat","dog","mouse","deer","lion"),
m=c(0.5,1,0.1,1.5,3),
kg=c(5,20,0.2,50,100),
code=c("A4","A5","A3","A1","A2"))
output<-data.frame(code=c("A1","A2","A3","A4","A5"))
output <- merge(output, input[, c("code", "kg")], by = "code",
all.x = TRUE, all.y = FALSE)
print(output)

Combining many vectors into one larger vector (in an automated way)

I have a list of identifiers as follows:
url_num <- c('85054655', '85023543', '85001177', '84988480', '84978776', '84952756', '84940316', '84916976', '84901819', '84884081', '84862066', '84848942', '84820189', '84814935', '84808144')
And from each of these I'm creating a unique variable:
for (id in url_num){
assign(paste('test_', id, sep = ""), FUNCTION GOES HERE)
}
This leaves me with my variables which are:
test_8505465, test_85023543, etc, etc
Each of them hold the correct output from the function (I've checked), however my next step is to combine them into one big vector which holds all of these created variables as a seperate element in the vector. This is easy enough via:
c(test_85054655,test_85023543,test_85001177,test_84988480,test_84978776,test_84952756,test_84940316,test_84916976,test_84901819,test_84884081,test_84862066,test_84848942,test_84820189,test_84814935,test_84808144)
However, as I update the original 'url_num' vector with new identifiers, I'd also have to come down to the above chunk and update this too!
Surely there's a more automated way I can setup the above chunk?
Maybe some sort of concat() function in the original for-loop which just adds each created variable straight into an empty vector right then and there?
So far I've just been trying to list all the variable names and somehow get the output to be in an acceptable format to get thrown straight into the c() function.
for (id in url_num){
cat(as.name(paste('test_', id, ",", sep = "")))
}
...which results in:
test_85054655,test_85023543,test_85001177,test_84988480,test_84978776,test_84952756,test_84940316,test_84916976,test_84901819,test_84884081,test_84862066,test_84848942,test_84820189,test_84814935,test_84808144,
This is close to the output I'm looking for but because it's using the cat() function it's essentially a print statement and its output can't really get put anywhere. Not to mention I feel like this method I've attempted is wrong to begin with and there must be something simpler I'm missing.
Thanks in advance for any help you guys can give me!
Troy

Use of quotes within get function (get())

I hope to get some help on the use of quotation marks within a string for get().
Say, I want to retrieve an element from a list
some_list <- list(element1=11,element2=22,element3=33)
naturally, I can simply reference this element through
some_list[['element1']]
However, once I use this as a string within get(), R throws this error message
get("some_list[['element1']]")
> Error in get("some_list[['element1']]") :
object 'some_list[['element1']]' not found
I cannot figure out why this is the case. get() works fine when used with strings that do not have quotation marks within them, e.g.
get("some_list")
I also tried escaping the quotation marks within the string (although I don't this I would need to since they are single quotation marks) but it does not work either.
some_list[["\'"element1"\'"]]
What am I missing.
get won't do that.
some_list[['element1']] isn't the name of an object in an R environment (in a technical sense). When you type some_list[['element1']] at the console, R parses the expression, looks up the symbol some_list and then calls the function [[. get is intended just for the symbol lookup piece of that.
(Technically, my sequence of events there probably isn't right, but I listed them that way to help make the issue clear. Really, R is just parsing the expression, and then calling [[ with arguments some_list and 'element1', and those symbols are subsequently looked up.)
The quotes have nothing to do with it. Run:
get("some_list")[['element1']]

Resources