How to make the strip text in 1 row? - r

a part of my facet-wrap command structure contains this:
facet_wrap(scales= "free",day~type~cellline)
and the strips I got spread in 3 lines and make up a lot of space so I want them just in 1 line. (DAY1 K562 Parent)
How can I do that?

Related

How to make a line of code span multiple lines in R where a new-line isn't created? Picture of desired outcome included

I'm trying to make a comment spanning multiple lines, but want them all to be the same line.
As in, Line 1 starts a comment that goes on to cover more lines, but each new line doesn't need a new '#' and Line 2 doesn't start until the comment is done.
Picture shows what I want in lines 3 and 5
You can use strings!
"
Module 4 Lecture 3: 911 call times
You have 250 datapoints of the time it takes to answer and resolve a
911 call saved in a csv file called 911TaskTimes.csv
You want...
"
Here's more information

Print first few lines of a text file in R

I have a text file with no apparent tabular or other structure, for example with contents
some text on line 1
some more text on line 2
even more text on the third line
etc
What is the most elegant and R-like way to print out the first few (say 2) lines of text from this file to the console?
Option 1: readLines
readLines('file.txt', n=2)
# [1] "some text on line 1" "some more text on line 2"
The n=2 option is useful, but I want the raw file contents, not the individual lines as elements of a vector.
Option 2: file.show
file.show('file.txt')
# some text on line 1
# some more text on line 2
# even more text on the third line
# etc
This output format is what I would like to see, but an option to limit the number of lines, like n=2 in readLines, is missing.
Option 3: system('head')
system('head -n2 file.txt')
# some text on line 1
# some more text on line 2
That's exactly the output I would like to get, but I'm not sure if this works on all platforms, and invoking an external command for such a simple task is a bit awkward.
One could combine the readLines solution with paste and cat to format the output, but this seems excessive. A simple command like file.head would be nice, or a n=2 argument in file.show, but neither exists. What is the most elegant and compact way to achieve this in R?
To clarify the goal here: This is for a write up of an R tutorial, where the narrative is something like "... we now have written our data to a new text file, so let's see if it worked by looking at the first couple of lines ...". At this point a simple and compact R expression, using base (update: or tidyverse) functions, to do exactly this would be very useful.
Use writeLines with readLines:
writeLines(readLines("file.txt", 2))
giving:
some text on line 1
some more text on line 2
This could alternately be written as the following pipeline. It gives the same output:
library(magrittr)
"file.txt" %>% readLines(2) %>% writeLines

How do parse a text file for the line after a phrase in r?

I have a large text file with 40,000+ sections of output. Each output section is ~150 lines. I want one number from each section to put in a vector. The section I want to parse is shown as below.
Min ChiSq_Th: ith_cs ith_rk
-1 1
chisq_th chisq_th_min chisq_th_max ftmp_imv fstp_imv
0.149282D+05 0.200268D+05 0.200268D+05 0.100000D+01 0.100000D+00
I need the number below chisq_th in each sweep. I tried taking every 152nd line but not every sweep is exactly the same. I know R is not the ideal platform for this problem but it is the language I know best.

Find lines matching a pattern, provided their value in a specified column occurs exactly twice in the input file

Say the input is (.csv file):
a,b_b,3,c
d,k_k,3,f
g,h_h,3,i
j,k_k,4,l
m,n_n,4,o
p,k_k,5,q
r,s_s,5,t
I want this output:
All lines containing the pattern "k_k" whose number in the third column is found in exactly two lines (ex.: numbers 4 and 5):
j,k_k,4,l
p,k_k,5,q
It might be a simple one but I can't find I way to achieve this. Could anyone help me using Unix command lines (awk)?
awk '/k_k/' && ?? file.csv
I think you want something like this:
awk -F, 'FNR==NR{a[$3]++;next} /k_k/ {if(a[$3]==2)print $0}' file file
I am assuming you mean that the number in column 3 appears exactly twice in the file, not that it is the number 4 or 5. This solution makes 2 passes over your file to count the number of times each number occurs in column 3 the first time and to print matching lines the second time. Therefore the input file is specified twice on the command line.
As a note of explanation, it counts the number of times 1 occurs in column 3 in a[1], and it counts the number of times 2 occurs in column 3 in a[2] etc...
Reading your question title, it says "2 lines maximum", so if occurring in one single line is also ok, you should change the "==" in my code to "<=". I cannot tell what you mean.

turning text into paginated two-column format and pipe this into less

I want to read a long text file in two-column format on my terminal. This means that the columns must be page-aware, so that text at the bottom of the first column continues at the top of the second column, but text at the bottom of the second column continues at the beginning of the first column after a page-down.
I tried column and less to get this result, but with no luck. If I pipe the text into column, it produces two columns but truncates the text before it reaches the end of the file. And if I pipe the output of column into less, it also reverts back to single-column.
a2ps does what I want in the way of reformatting, but I would rather have the output in pure plain text, readable from the terminal, rather than a PostScript file that I would need to read in a PDF reader.
You can use pr for this, eg.
ls /usr/src/linux/drivers/char/ | pr -2 |less

Resources