R package patchwork : titles for rows/columns - row

Is there a way to add titles by row or column using the patchwork package for combining plots?
Ex. with the arrangement : patchwork<- (p| p2 | p3)/ (p4| p5| p6), I would like one title for plots 1-3 and another for 4-6.

Related

Is a font record index in BIFF8 zero-based?

I am programmatically reading and writing an Excel worksheet, using the source code from https://www.codeproject.com/articles/13852/basicexcel-a-class-to-read-and-write-to-microsoft, which in turn is based on the documentation of the Excel file format from http://sc.openoffice.org/excelfileformat.pdf.
The Excel file format supported by the source code is Binary Interchange File Format version 8 (BIFF8).
One of the records in an Excel file is an Extended Format (XF) record. The first two bytes of the XF record is an index to a FONT record. That is all the documentation has to say about it.
My question: Is that a zero-based index or a 1-based index?
The following is a use case that confused me and lead me to ponder this question.
Use case: bold cell
I created a simple Excel worksheet: one cell containing text that is bold.
I programmatically read that Excel worksheet and dump all the data to a human readable format, using new dump() methods I added to the source code. I find that:
My cell is associated with a LABELSST record: <LabelSST rowIdx=0 colIdx=0 xfRecIdx=62 sstRecIdx=0 />
That LABELSST record refers to an XF record with an index of: 62
If that is a zero-based index, the XF record at index 62 is: <XF fontRecIdx=20 formatRecIdx=0 protect=0x1 align=0x20 rot=0 text=0 usedAttribs=0x8 borderLines=0 color1=0x2000000 color2=0x20c0 />
That XF record refers to a FONT record with an index of: 20
If that is a zero-based index, the FONT record at index 20 is: <Font height=220 options=0 colorIdx=9 weight=400 escType=0 uline=0 family=2 charSet=0 name="Calibri" />
That FONT record has a weight of 400.
That font weight of 400 is not what I expected. If my cell content is bold, then the font weight should be 700, as per the documentation.
However, if the XF record refers to a FONT record with a 1-based index, then FONT record at 1-based index 20 is: <Font height=220 options=1 colorIdx=8 weight=700 escType=0 uline=0 family=2 charSet=0 name="Calibri" />
And that FONT record does indeed have a weight of 700 to indicate bold.
This is confusing. I do not know if the index to FONT record in the XF record is supposed to be zero-based or 1-based.
I think I found the answer to my own question elsewhere in the http://sc.openoffice.org/excelfileformat.pdf documentation.
The font with index 4 is omitted in all BIFF versions. This means the first four fonts have zero-based indexes, and the fifth font and all following fonts are referenced with one-based indexes.
If that is true, then the data I observed makes more sense.

Python-docx - How to change table font size?

table = document.add_table(rows=1, cols=1)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
I have to change font size of text 'Qty' in table with one row and one column, how can I make it?
You need to get the paragraph in the cell. From the documentation of python-docx:
3.5.2 _Cell objects:
class docx.table._Cell (tc, parent)
paragraphs
List of paragraphs in the cell. A table cell is required to
contain at least one block-level element and end with a paragraph. By
default, a new cell contains a single paragraph. Read-only
Reference: python-docx Documentation - Read the Docs
The code:
To change font size of text 'Qty'
paragraph =hdr_cells[0].paragraphs[0]
run = paragraph.runs
font = run[0].font
font.size= Pt(30) # font size = 30
To change font size of the whole table:
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
for paragraph in paragraphs:
for run in paragraph.runs:
font = run.font
font.size= Pt(30)
Reference of how to access paragraphs in a table: Extracting data from tables
Up there the solution really helped. I use it for a while. But I found a tiny problem:time. As your table grows bigger the time you cost to build the table getting longer. So I improve it. Cut two rounds. Here you are:
The code changes the whole table
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
paragraph = paragraphs[0]
run_obj = paragraph.runs
run = run_obj[0]
font = run.font
font.size = Pt(30)
When you cut two rounds you save the time
Building on user7609283 answer, here is a short version to set a cell to bold (the cell must contain text before applying format as it looks for the first paragraph):
row_cells = table.add_row().cells
row_cells[0].text = "Customer"
row_cells[0].paragraphs[0].runs[0].font.bold = True
This font change applies to all cells of a table and is streamlined. All cells must contain text before being formatted or an index out of range error is thrown:
for row in table.rows:
for cell in row.cells:
cp = cell.paragraphs[0].runs
cp[0].font.size = Pt(14)
This next font change applies to a single cell as wanted, in this case the top left cell:
tc = table.cell(0, 0).paragraphs[0].runs
tc[0].font.size = Pt(14)

source file fixed width , need only Header and Footer to the target(oracle)

I have this scenario with source as fix width flat file, and I need to read to target only the Header and Footer not the details records.
I need to trim the first column (PA22109 ) and get only PA and next 2 columns to rows as two different dates.
For Footer get only the PT(PT000000000700000030620E00000055612I00000010277I) and the rest into a column of the target.
How can I achieve this logic, inputs are appreciated.
source file :
PA22109 00153252015110905408179 2015110820151108PO ---header
DE0E9D TESTGROUPEXCH TESTINSEXCH TESTLOCEXCH ID014 LNAME014 FNAME014 14 MAIN ST ANYWHERE NJ011110000 195001012Z 01000000014 LNAME014 PATFIRST014 14 MAIN ST ANYWHERE NJ011110000 1955010110106000220 TESTGROUPEXCH 8179 TESTBENEXCH TESTCNTE53 0000000000 0000002643005 011234567890 011234567890 1234 TEST PHARMACY TEST PHARMACY LANE PHARMACYTOWN NJ09876 5555555555 11Y5 019876543210 019876543210 NJPRESCLAST PRESCFIRST 5555555551 DRLAST DRFIRST 110110000009770990300406048410 2015092720150927154401000000000000120150929 0000100000000000000000000000000
PT000000000700000030620E00000055612I00000010277I --Footer
As this a fixed file you can perform following to meet your requirement.
In your Informatica mapping, Read row in a single column.
In Expression, Mark each record for filter out if It does not start with PA OR PT (Assumption your Detail records do not start with PA or PT). Filter detail record out using Filter transformation.
Now you have only Header and Footer Records.
Now you can apply respective condition in expression for PA and PT Records.

python igraph Error at fast_community.c:553

First, thanks for reading and possibly responding to this.
Now, the question:
I am on python 2.7, and I am getting this error when attempting to find communities in my graph using the fastgreedy algorithm:
---------------------------------------------------------------------------
InternalError Traceback (most recent call last)
<ipython-input-180-3b8456851658> in <module>()
----> 1 dendrogram = g_summary.community_fastgreedy(weights=edge_frequency.values())
/usr/local/lib/python2.7/site-packages/igraph/__init__.pyc in community_fastgreedy(self, weights)
959 in very large networks. Phys Rev E 70, 066111 (2004).
960 """
--> 961 merges, qs = GraphBase.community_fastgreedy(self, weights)
962
963 # qs may be shorter than |V|-1 if we are left with a few separated
InternalError: Error at fast_community.c:553: fast-greedy community finding works only on graphs without multiple edges, Invalid value
This is how I created my graph:
import igraph as ig
vertices = words #about 600 words from a number of news articles: ['palestine', 'israel', 'hamas, 'nasa', 'mercury', 'water', ...]
gen = ig.UniqueIdGenerator()
[gen[word] for word in vertices] #generate word-to-integer mapping as each edge has to be between integer ids (words)
edges = []
for ind in xrange(articles.shape[0]): # articles is a pandas dataframe; each row corresponds to an article; one column is 'top_words' which includes the top few words of each article. The above list *words* is the unique union set of top_words for all articles.
words_i = articles['top_words'].values[ind] # for one article, this looks like ['palestine','israel','hamas']
edges.extend([(gen[x[0]],gen[x[1]]) for x in combinations(words_i,2)]) #basically there is an edge for each pair of top_words in a given article. For the example article above, we get edges between israel-palestine, israel-hamas, palestine-hamas.
unique_edges = list(set(edges))
unique_edge_frequency = {}
for e in unique_edges:
unique_edge_frequency[e] = edges.count(e)
g = ig.Graph(vertex_attrs={"label": vertices}, edges=unique_edges, directed=False)
g.es['width'] = np.asarray([unique_edge_frequency[e] for e in unique_edge_frequency.keys()])*1.0/max(unique_edge_frequency.values())
And this is what throws the error:
dendrogram = g.community_fastgreedy(weights=g.es['width'])
What am I doing wrong?
Your graph contains multiple edges (i.e. more than one edge between the same pair of nodes). The fast greedy community detection won't work on such graphs; you have to collapse the multiple edges into single ones with g.simplify().
It also seems like you are trying to set the "width" attibute of the edges based on how many edges there are between the same pair of vertices. Instead of constructing unique_edges and then unique_edge_frequency, you can simply do this:
g = Graph(edges, directed=False)
g.es["width"] = 1
g.simplify(combine_edges={ "width": "sum" })
This will simply create a graph with multiple edges first, then assign a width of 1 to each edge, and finally collapse the multiple edges into single ones while summing up their widths.

VBA Excel : Read file, and stock images in a column

I am new to VBA (I mean, REALLY new) and I would like you to give me some tips.
I have an Excel file with 2 columns: SKU and media_gallery
I also have images stocked in a folder (lets name it /imageFolder)
I need to parse the imageFolder and look for ALL images sarting by SKU.jpg , and put them into the media_gallery column separated by a semicolon ( ; )
Example: My SKU is "1001", I need to parse the image folder for all images starting by 1001 (all image have this pattern: 1001-2.jpg , 1001-3.jpg etc...)
I can do that in Java or C# but I want to give a chance to VBA. :)
How can I do that?
EDIT: I only need file names yes! And I should of said that I have 20 000 images in my folder, and 8000 SKUs , so I don't know how we can handle looping on 20 000 images names.
EDIT2: If SKU contains a dash ( - ), I don't need to treat it, so I can pass to the next SKU. And each SKU has a maximum of 5 images (....;SKU-5.jpg)
Thanks all.
How to insert images given you have one image name per cell in a column: How to get images to appear in Excel given image url
Take the above and introduce an inner loop for the file name:
if instr(url_column.Cells(i).Value, "-") = 0 then
dim cur_file_name as string
cur_file_name = dir("imageFolder\" & url_column.Cells(i).Value & "*.jpg")
do until len(cur_file_name) = 0
image_column.Cells(i).Value = image_column.Cells(i).Value & cur_file_name & ";"
cur_file_name = Dir
loop
end if