Microsoft Power Apps formula chaining in a data card value field - formula

I have data coming as {"abc", 1, CE}. I would like to replace the braces and split it and display it in a data card. I want the first function output to be the input of the second function
First I am trying to use Substitute to replace the curly braces and it's not working.
I tried the following
Substitute(Parent.Default,"{","");Substitute(Parent.Default,"}","");
Substitute(Parent.Default,"{","");;Substitute(Parent.Default,"}","");;
Text(Concurrent(Substitute(Parent.Default,"{","");;Substitute(Parent.Default,"}","")))
Text(Concurrent(Substitute(Parent.Default,"{","");Substitute(Parent.Default,"}","")))
The following works fine with just one.
Substitute(Parent.Default,"{","")

The Substitute function doesn't change the argument that you pass to it; instead, it returns a new string with the substitution applied. So if you want to remove both curly braces, you need to use an expression similar to the one below:
Substitute(Substitute(Parent.Default, "{", ""), "}", "")

Related

How can I replace "map-09" by `map-09` in R? (from double quotes to single quotes)

I tried with gsub, and str_replace, but I didn't get what I need.
gsub("\"", "\`", "map-09", fixed=TRUE)
gives "map-09" and not map-09
str_replace("map-09","\"","\`")
gives "map-09" and not map-09
I think you're getting confused between the way the string is being represented vs. what the string actually is. The functions you're using don't actually add any quotes. But when the output is printed quotes are there to show you that it is a string being represented. If you use the function 'cat' to print the output you'll see it without the quotes.
See the difference between
print("example")
cat("example")

Method to paste whisker template

I am writing a program to generate whisker template in a loop, and I want to paste them together. For every template, my code looks like this:
script[i] <- whisker.render(template_pdf[i], data = parameter)
Is there a method to paste all the script[i] together? I know I can paste all the chunks first and then use function whisker.render just for one time, but that will cause some trouble in my particular case. If I can paste all the script[i] together, that will be convenient for me.
When script is a character vector you can do
paste(script, collapse = "\n")
with \n (newline) the character inserted between the script elements.
When script is a list, you can do
do.call(paste, c(script, sep ="\n"))

Match everything up until first instance of a colon

Trying to code up a Regex in R to match everything before the first occurrence of a colon.
Let's say I have:
time = "12:05:41"
I'm trying to extract just the 12. My strategy was to do something like this:
grep(".+?(?=:)", time, value = TRUE)
But I'm getting the error that it's an invalid Regex. Thoughts?
Your regex seems fine in my opinion, I don't think you should use grep, also you are missing perl=TRUE that is why you are getting the error.
I would recommend using :
stringr::str_extract( time, "\\d+?(?=:)")
grep is little different than it is being used here, its good for matching separate values and filtering out those which has similar pattern, but you can't pluck out values within a string using grep.
If you want to use Base R you can also go for sub:
sub("^(\\d+?)(?=:)(.*)$","\\1",time, perl=TRUE)
Also, you may split the string using strsplit and filter out the first string like below:
strsplit(time, ":")[[1]][1]

Nesting more than two types of quotes in R

I would like to know how to accommodate more than two types of quotes in a same row in R. Let´s say that I want to print:
'first-quote-type1 "first-quote-type2 "second-quote-type2
'sencond-quote-type1
Using one quote in the beginning and one in the end we have:
print("'first-quote-type1 "first-quote-type2 "second-quote-type2 'sencond-quote-type1")
Error: unexpected symbol in "print("'first-quote-type1 "first"
I tried to include triple quotes as required in Python in this cases:
print(''''first-quote-type1 "first-quote-type2 "second-quote-type2 'sencond-quote-type1''')
print("""'first-quote-type1 "first-quote-type2 "second-quote-type2 'sencond-quote-type1""")
However, I also got a similar error. Some idea how to make this syntax work in R?
To use a quote within a quote you can escape the quote character with a backslash
print("the man said \"hello\"")
However, the print function in R will always escape character.
To not show the escaped character use cat() instead
so...
cat("the man said \"hello\"") will return
the man said "hello"

Difference between paste and print (affecting result of function)

To start off, I'm not really sure what the difference between paste and print is. But I am using "print" to spit out generic statements and "paste" to spit out statements that use/ reference specific variables.
My issue is that when using paste within a function, I am losing my pasted output if there is anything included in the function following the "paste" statement.
Please see the following three functions:
TS<-5
Example 1- everything works fine
T<-function(){
if(exists("TS"))
{paste("TS= ", TS, sep=" ")}
else
if(!exists("TS"))
{print.noquote("No TS Values")}
}
Example 2- My Problem. When I add anything (in this case another print command) following my "if" statement I will lose my pasted output
T<-function(){
if(exists("TS"))
{paste("TS= ", TS, sep=" ")}
else
if(!exists("TS"))
{print.noquote("No TS Values")}
print("my exsistance removes paste output")
}
Example 3- The same statement placed before the "if" has no negative effect
T<-function(){
print("my exsistance does not remove paste output")
if(exists("TS"))
{paste("TS= ", TS, sep=" ")}
else
if(!exists("TS"))
{print.noquote("No TS Values")}
}
Can someone explain where the conflict is within this function. And better yet how can I work around it so that I can have a paste statement followed by other actions within a function
basically how can I get example #2 to work.
Brownie points- (for sake of visual consistency) when using "print.noquote", is there such a thing as a paste.noquote?
paste concatenates (pastes) strings and returns a character vector, so you can do thing like
paste('a','b', sep = '-')
## [1] "a-b"
print prints values. From ?print
print prints its argument and returns it invisibly (via invisible(x)). It is a generic function which means that new printing methods can be easily added for new classes.
Most classes will have a defined print method (or will use print.default)
You can see the available print methods by typing
methods('print')
In your case
paste("TS= ", TS, sep=" ") returns a character vector, so when this is the result of the function, print.character is used to display the results
In fact, I think you want message not print or print.noquote.
T <- function() {
if (exists("TS"))
{
message(paste("TS= ", TS, sep=" "))
} else if (!exists("TS")) {
message("No TS Values")
}
message("my exsistance removes paste output")
}
paste returns the input concatenated together. When a function returns it calls print on whatever was returned if it isn't stored into a variable. Functions return the last top level call if there is no explicit 'return' or 'invisible' statement.
All of these things add up to what you end up seeing. If paste is the last function called it ends up returning the input concatenated together - which ends up being returned by the function - which ends up being printed since you don't save it into a variable. If you explicitly want something printed it is best to use print or message or cat - they each serve slightly different purposes.

Resources