Dumb question, in Atom, how do you replace (2) newlines with (1)?
Related
I have a long character that comes from a pdf that I want to process.
I have recurring instances of Table X. Name of the table, that in my character are always followed by a \r\n
However, when I try to extract all the tables in a list, using List_Tables <-str_extract_all(Plain_Text, "Table\\s+\\d+\\.\\s+(([A-z]|\\s))+\\r\\n"), I do have often another line that is still in my extraction, e.g.
> List_Tables
[[1]]
[1] "Table 1. Real GDP\r\n Percentage changes\r\n"
[2] "Table 2. Nominal GDP\r\n Percentage changes\r\n"
What have I missed in my code ?
\s matches all whitespace, including line breaks! When combined with the greedy quantifier +, this means that (([A-z]|\\s))+ matches, in your first example,
Real GDP\r\n […] Percentage changes\r\n
The easiest way to fix this is to use a non-greedy quantifier: i.e. +? instead of +.
Just for completeness’ sake I’ll mention that there are alternatives, but they get more complicated. For instance, you could use negative assertions to include an “if” test to match whitespace which isn’t a line break character; or you could use the character class [ \t] instead of \s, which is more restrictive but also more explicit and probably closer to what you want.
I want to count the number of lines generated by a command substitution $(blah) using zsh instead of piping through wc -l. I know how to turn the command substitution lines into an array, like this:
blah_output=(${(f)"$(blah)"})
…and counting the number of items in an array is just this:
${#blah_output}
My question is: how can I do that in one expression, without the intermediate variable? After some fiddling, I came up with this:
${#${(f)"$(blah)"}}
…which works unless blah returns only one line, at which point it returns the number of characters in that line, and I don't understand why or how to fix it. What's the real answer? Is there one?
Sub-questions:
When creating the initial array, I don't understand why the outer parentheses are necessary; I expected that splitting would imply an array value.
I don't understand why the quotes around $(blah) are necessary; if I don't include them, I get one element with the line break transformed into a space. Something about an implicit word split and then join?
I have given an assignment and the question is:
Suppose you were working a word puzzle and needed a 5-letter word beginning with a vowel (including ‘y’) in upper- or lower-case, a lower-case ‘t’ in the third position, and ending with a lower-case ‘s’.
The remaining letters could be any character that occurs in English words, including upper and lower-case alphabetics, numbers, hyphens, etc. (We will accept the file /usr/share/dict/words as the authority on what constitutes a valid English word and what characters can appear within one.)
What grep command would you use to list the words from /usr/share/dict/words that match this requirement?
I have tried a lot of commands and I can not seem to get it. Is there any kind of hint someone could give me towards the
answer?
I have spend hours to look for a proper solutions but I found nothing on Internet. There is my question. In R, I have a specific list of characters containings my desired variable names ("2011_Q4", "2012_Q1", ...). When I try to assign a dataset to each of this name with a loop, it does work but the output it's strange. Indeed, I have
> View(`2011_Q4`)
instead of
> View(2011_Q4)
And I don't know how to remove this apostrophe. It's very annoying since I have to type this ` in order to call the variable.
Somebody can help me? I would appreciate his help.
Thanks a lot and best regards
Firstly, it's a backtick (`), not an apostrophe ('). In R, backticks occasionally denote variable names; apostrophes work as single quotes for denoting strings.
The issue you're having is that your variables start with a number, which is not allowed in R. Since you somehow made it happen anyway, you need to use backticks to tell R not to interpret 2011_Q4 as a number, but as a variable.
From ?Quotes:
Names and Identifiers
Identifiers consist of a sequence of letters, digits, the period (.)
and the underscore. They must not start with a digit nor underscore,
nor with a period followed by a digit. Reserved words are not valid
identifiers.
The definition of a letter depends on the current locale, but only
ASCII digits are considered to be digits.
Such identifiers are also known as syntactic names and may be used
directly in R code. Almost always, other names can be used provided
they are quoted. The preferred quote is the backtick (`), and deparse
will normally use it, but under many circumstances single or double
quotes can be used (as a character constant will often be converted to
a name). One place where backticks may be essential is to delimit
variable names in formulae: see formula.
The best solution to your issue is simply to change your variable names to something that starts with a character, e.g. Y2011_Q4.
I have a very long expression that I need to take the derivative of:
D(expression(-4750000+(((14400*(((x/25)*1)-7.2))+(0*((x*1.05)-7.2))+(144*
((x*0.6)-7.2))*30.41667)-2500)/((0.1+1)^((1-0.5)/12))+(((13216.5802942644*
(((x/25)*1)-7.2))+(0*((x*1.05)-7.2))+(132.165802942644*
((x*0.6)-7.2))*30.41667)-2500)/((0.1+1)^((2-0.5)/12))+.........),'x')
When the expression is less than 4000 characters I get a solution. When it is more than 4000 characters, R gives me a newline and +, expecting more input. I haven't been able to find documentation on a character limit. Does anyone know why this might be? Any workarounds or alternatives to finding this derivative? The final character length will be at least 50k.
You are probably seeing an effect of input through stdin which uses the OS newline function. Try putting it in a text file and source()-ing.