expression() command in R with semicolons - r

In the output of the following code,
curve((1+exp(-1*x))^-1,
xlim=c(-10,10),ylim=c(0,1),
main="Logistic function",xlab=expression ("x"[t-d]),
ylab=expression ("G"("x"[t-d],gamma,c)))
In the y-axis label, how to place a semi-colon in between immediately before the gamma instead of a comma?

In this case you just need to think of the semicolon as text rather than a special character you can do
ylab=expression ("G"("x"[t-d]~";"~gamma,c))
or you can use * rather than ~ if you want less space.

Related

What do these characters inside the parentheses of a paremeter expansion (${(…)}) do?

hi am new to zsh and am trying to create multi-line prompt and came across this line of code:
local pad=${(pl.$pad_len.. .)}
My 1st question is what is the pl inside the parentheses? Is it a command or operator or a flag(s)?
And my 2nd question is what are the dots that follow $pad_len?
Those are Zsh parameter expansion flags.
l.$pad_len. makes the given (in this case, empty) string exactly $pad_len long, either by truncating it from the left or by padding it on the left with spaces.
l.$pad_len.. . does the same as the above, but specifies explicitly to use the space character for padding — which is unnecessary, since the default is to pad with spaces.
The .s here are arbitrary separators used to enclose each argument for the preceding flag. It doesn’t matter which (matching pair of) punctuation characters you use for this, as long they enclose each argument in pairs. So, l:$pad_len:: : and l<$pad_len>< > do the exact same thing.
p makes l support print escape codes in the second argument — which is unnecessary, since we don’t use any here.
So, a shorter way to write this would be
local pad=${(l.$pad_len.)}
If you want to do this operation on a non-empty string, you can either pass the name of a variable
local foo=bar
local pad=${(l.$pad_len.)foo}
or pass a literal string with :-
local pad=${(l.$pad_len.):-bar}

Functions to format text for base R plotting

Specifying text in a base R plot() with formatting such as italics / bold font / newline usually involves one or more of the following functions:
paste()
expression()
atop()
substitute()
italic()
Is there an intuitive explanation for the differences between these functions and when best to apply them?
What you're referring to is the plotmath syntax.
To start off, let's make it clear that for a plotmath expression to be interpreted as such, you tell R it's an "expression" and that is why you need expression().
So any time you want to use special symbols or formatting, like italic() and atop(), it's actually a part of plotmath and so you need to wrap it in an expression. eg:
plot(0, main = expression(atop(over,italic(under))))
If you've tried out ?italic or ?atop, you've probably noticed it takes you straight to the plotmath manual page, where a bunch of other functions are listed.
What about substitute() ? Well in my previous example, you'll notice I used strings directly to write 'over' and 'under', without putting them within quotes. This is because of the special expression() environment.
So if you need to put whatever is inside a variable in your text (rather than the variable name) then you put your expression inside a substitute() and give it the arguments. eg:
plot(0, main = substitute(atop(oo,italic(under))), list(oo='over2')))
Note that we don't put substitute around the expression block but replace it entirely.
Finally, where does paste() come in all this ? Well, paste is the glue (pun intended) with any text not dealt with by plotmath.
So if you need text before or after math symbols (or formatted text), you paste() things together within the expression (or substitute) environment. eg :
plot(0, main = substitute(paste("b4", atop(oo,italic(under)), aft),
list(oo='over', aft = 'after3')))
As before, if you want to paste the content of a variable, you need substitute.
And Voilà that's most of the plotmath you'll ever need!
For any other symbols, or functions, have look at ?plotmath

Subscripts in R when adding other text

How would you add a subscript to one particular word of a title in R? For example, suppose the title is "A_2 and B_2." How would you add these two subscripts? I know that expression("A"[2]) and expression("B"[2]) individually add subscripts to these letters.
You do not need paste (or quotes for that matter) at all:
expression( A[2]~and~B[2] )
Test:
plot(1,1, main=expression( A[2]~and~B[2] ) )
The syntactic principle is that tildes (which creates a space) and asterisks (non-space plotmath separator) are used to separate items and that no quotes are needed unless you are using a plotmath function name .... such as wanting the word "paste" or "sqrt" to appear in the displayed version of the expression.
Just paste them together:
expression(paste("A"[2], " and B"[2])

RegEx for Client-Side Validation of FileUpload

I'm trying to create a RegEx Validator that checks the file extension in the FileUpload input against a list of allowed extensions (which are user specified). The following is as far as I have got, but I'm struggling with the syntax of the backward slash (\) that appears in the file path. Obviously the below is incorrect because it just escapes the (]) which causes an error. I would be really grateful for any help here. There seems to be a lot of examples out there, but none seem to work when I try them.
[a-zA-Z_-s0-9:\]+(.pdf|.PDF)$
To include a backslash in a character class, you need to use a specific escape sequence (\b):
[a-zA-Z_\s0-9:\b]+(\.pdf|\.PDF)$
Note that this might be a bit confusing, because outside of character classes, \b represents a word boundary. I also assumed, that -s was a typo and should have represented a white space. (otherwise it shouldn't compile, I think)
EDIT: You also need to escape the dots. Otherwise they will be meta character for any character but line breaks.
another EDIT: If you actually DO want to allow hyphens in filenames, you need to put the hyphen at the end of the character class. Like this:
[a-zA-Z_\s0-9:\b-]+(\.pdf|\.PDF)$
You probably want to use something like
[a-zA-Z_0-9\s:\\-]+\.[pP][dD][fF]$
which is same as
[\w\s:\\-]+\.[pP][dD][fF]$
because \w = [a-zA-Z0-9_]
Be sure character - to put as very first or very last item in the [...] list, otherwise it has special meaning for range or characters, such as a-z.
Also \ character has to be escaped by another slash, even inside of [...].

Removing the Default Wrap Character From all records

I am using BizTalk 2009 and I have a flat file that is similar to the following
"0162892172","TIM ","LastName ","760 "," ","COMANCHE ","LN "
"0143248282","GEORGE ","LastName ","625 "," ","ENID ","AVE "
When I parse it and start mapping it I need to get rid of the quotation marks. I have marked the Wrap Character attribute for the schema as a quotation mark but it doesn't remove it when BizTalk is parsing the file.
Is there an easy way to specify the removal of a wrap character or am I going to have to run it through a script functiod every time? Also I would like to be able to remove the trailing spaces as well, if at all possible.
If you're still seeing the quotes after parsing, it likely means you set the wrap character property incorrectly. Are you sure you also set Wrap Character Type == Character?
As for the extra spaces, those will be hard to get rid of during parsing, because the quotes would specifically tell bts that they were intentional, so yeah, your best bet is to probably remove those during mapping or whatever.
this page seems to suggest that removing the trailing spaces can be done with:
> Pad Character Type = Hexadecimal
> Pad Character = 0x20

Resources