I want to the following text to appear on a heatmap.3 key "value": (\n to allow start on second line) Log2 Fold Change
Using the following code, I got this: Log[2] Fold Change:
paste0("\n", expression(Log[2])," Fold Change")
The newline worked and the text started started on the second line as required. But, how can I get rid of the []
expression part should be before paste; like here:
expression(paste("\n", Log[2], " Fold Change")) -> text
plot(1:10, xlab=text)
Related
I have a text like this:
"Hello how
are you" %>% word(-1)
I get an error if I perform this because I pressed Enter after how. How do I remove the hidden line break so as to perform my code on the text?
Ok, I found the exact mechanism to make this reproducible.
This happens under 2 conditions that are my default way to process code in R.
In a chunk
You don't execute the chunk, but the line pressing ENTER + CTRL
Solution: execute the chunk instead.
I know that functions are supposed to look like this:
my_function <- function(x) {
Body
}
My issue is that I can't get the symbol "{" and the symbol "}" on different lines. When I type start typing "my_function <- function(x) {" in the console, the closing brace immediately appears, and if I press enter at any point, I just get a new line.
To answer this specific question, if you delete the closing curly brace it adds before typing enter you can write multi-line functions like that. Also, if you copy/paste from another editor that will also work.
Also, you can disable the auto-brace adding feature by going to Tools->Global Options->Code->Editing and unchecking "Insert matching parens/quotes"
I have the following utilsnips script that I use for Vim:
snippet - "assignment"
<-
endsnippet
I use it for R to expand a dash to the assignment operator. I would like to make it so that a space is put both before and after the <- on expansion. However, when I put a space before it in the snippet like <-, it won't expand on hitting Tab. How should I modify the script to have spaces around the operator? Desired result: <-.
You could use r option to include head and trailing spaces around snippets. r will treat snippet as a python regular expression and you should define your snippet within quotes when using this flag.
snippet " -" "assignment" r
<-
endsnippet
Note that there is a space before and after <- in snippet definition.
As a bonus, It's more interesting to define the snippet like the following:
snippet " - " "assignment" rA
<-
endsnippet
A is autoexpansion. so now you dont need to hit tab anymore! just type - and as soon as you type space after - it will expand to <- Automatically.
I wish to print a text in the title in two lines but am not able to achieve desired output because of subscript present in the text. Following is the e.g of the text that I want in two lines.
plot(1,main=expression(paste(CO[2]~'Flux (kg C ', m^-2,' ',s^-1,')')))
BUT using line break as in following command does not give desired result of bringing (only) the text following it in new line:
plot(1,main=expression(paste(CO[2]~'Flux \n(kg C ', m^-2,' ',s^-1,')')))
Please help me with this issue.
Thanks in advance
You can do this with the atop function.
plot(1,main=expression(atop(CO[2]~'Flux', paste('(kg C ', m^-2,' ',s^-1,')'))))
Since the lheight par doesn't affect expressions, if you want tighter spacing between the lines, you can use the following.
plot(1,main=expression(textstyle(atop(CO[2]~'Flux', paste('(kg C ', m^-2,' ',s^-1,')')))),
cex.main=2)
I wish to include a subscript and a title running into two lines at the same time but am not getting desired result with following commands:
base<-'B1'
compare<-'A1'
plot (1, 1, main = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n' ~.(compare)~ 'minus'~.(base)))
I wish to insert a line break after 'Flux Difference' but its not happening instead this term is hanging nowhere. Please help me.
Thanks,
Munish
This is a fairly common request and there is no really clean answer. Plotmath will not accept a "\n" (and the help page documents this.) One dodge is to use each line as an argument to the plotmath function atop. The other plotmath trick sometimes of use is phantom with an empty argument list to allow the tilde not to throw an error, but that is not needed here:
plot (1, 1, main = bquote( atop('Annual mean' ~CO[2] ~'Flux Difference:' ,
.(compare)~ 'minus'~.(base))) )