Asked 1 year, 2 months ago. Active 1 year, 2 months ago. Viewed times. Lionel Duarte Lionel Duarte 51 4 4 bronze badges. I updated R to 3. It exports to pptx, word, and html fine. The default R studio viewer seems to have trouble though. It looses most of the color formatting in R studio notebooks as well when knitting just that chunk.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I am trying to make a FlexTable using the ReporteRs package. I want to be able to flexibly specify whether borders exist for each column and row using cols. Additionally, I would like to be able to include the darker borders at the top and bottom of the border of the table.
An example of column specification is shown below using the mtcars dataset, and an example of darker borders is shown using a subset of the iris dataset. David's response was very helpful, this is the code I will use, with some messiness at the end to allow zero to be in cols.
Learn more. Asked 2 years, 10 months ago. Active 2 years, 9 months ago. Viewed times. David Gohel 4, 2 2 gold badges 9 9 silver badges 22 22 bronze badges. Ben Ben 25 4 4 bronze badges. Active Oldest Votes. Not sure it answers exactly your question but at least you will get some code to play with. David Gohel David Gohel 4, 2 2 gold badges 9 9 silver badges 22 22 bronze badges.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project?
Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account. It seems the border properties of merged cells aren't respected when a table is exported in powerpoint. It looks fine in HTML however. Here's some example code:.
Note only half of the header bottom border is red. I've opened the ppt with Powerpoint and with same results. I'm running the github version of flextable. The problem seems to stem from conflicts between the borders of one cell and the overlapping borders of adjacent cells. In order for the border to show up as red, the "3" cell needs to have a red top border.
The same problem shows up in merged cells when the right border of one cell conflicts with the left border of the next cell to the right. Furthermore, the problem doesn't show up on the table edges, when there are no adjacent cells:. There is a pretty easy workaround for flextable users: simply set the relevant borders manually, e. However, arguably it would be better to handle this inside flextable. For instance, in the styles. R file, the border function could be modified to automatically set any interior border in two places: the specified cells and adjacent cell which shares that border if any.
I was going to prepare a patch in this direction, but then realized it could mess up other targets e. It would also be harder to keep track of table modifications e.
Subscribe to RSS
Perhaps it would be better instead to leave the border function as-is, and have an PPT-specific pass that fixes up conflicting borders before printing.
Or maybe there's another solution, or maybe it's best not to do anything and just have users use the workaround. Anyway, just reporting my initial findings here.These functions let control the horizontal or vertical borders of a flextable. They are sugar functions and should be used instead of function border that requires careful settings to avoid overlapping borders. The function is setting horizontal lines along the part part of the flextable object.
The lines are the bottom borders of selected cells. The function is setting the first horizontal line of the part part of the flextable object. The line is the top border of selected cells of the first row. The function is setting the last horizontal line of the part part of the flextable object. The line is the bottom border of selected cells of the last row. The function is setting vertical lines along the part part of the flextable object.
The lines are the right borders of selected cells. The function is setting the first vertical line of the part part of the flextable object. The line is the left border of selected cells of the first column. The function is setting the last vertical line of the part part of the flextable object. The line is the right border of selected cells of the last column. Created by DataCamp.
Community examples Looks like there are no examples yet. Post a new example: Submit your example. API documentation. Put your R skills to the test Start Now.An API is available to let you manipulate format, add text, merge cells, etc. A FlexTable is made of 3 parts: header, body and footer. To insert headers and footers rows with eventually merged cells, see addHeaderRow and addFooterRow.
set flextable right vertical borders
Formating can be done on cells, paragraphs and text borders, colors, fonts, etc. The classical workflow would be to create a FlexTable, to add headers rows see addHeaderRow and eventually footers rows see addFooterRow. A FlexTable lets you add text in cells and modify cells, paragraphs and text properties.
Apply a textProperties object to a subset of the FlexTable. The textProperties object will be used to format all text from selected cells. See alterFlexTable. Text can be added just after the last text in the cell or as a new paragraph. Format can also be specified. Text can also be a pot object if the text format is complex. Apply a parProperties object to a subset of the FlexTable. The parProperties object will be used to format all paragraphs from selected cells.
Apply a cellProperties object to a subset of the FlexTable. The cellProperties object will be used to format selected cells. Don't forget to specify argument side.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. This is relatively simple using flextable, but becomes a bore with a much larger data set. I cannot see a way to do this more efficiently. I could use dplyr to pre-process the data although the comma formatting requires changing the variable type from double to character.
I'd prefer if possible to do this in flextable. I'm aware multi-column formatting is possible with Huxtable. Learn more. Formatting multiple columns with flextable r package Ask Question.
Asked 2 years ago. Active 2 years ago.
set horizontal borders
Viewed 2k times. Is it possible to format multiple columns with one line of script using flexitable? The example includes variables of two different types of double. I'd like to: round variables greater than to the nearest and add thousand comma formating, and round variables less than one to two decimal places This is relatively simple using flextable, but becomes a bore with a much larger data set.
MWE set. Peter Peter 99 8 8 bronze badges. Active Oldest Votes. David Gohel David Gohel 4, 2 2 gold badges 9 9 silver badges 22 22 bronze badges. Sorry, I cannot seem to apply the links to format multiple columns without a separate line of code for each column.I love the formattable package, but I always struggle to remember its syntax.
A quick Google search reveals that I'm not alone in this struggle. This post is intended as a reminder for myself of how the package works - and hopefully you'll find it useful too! The table below is an R data frame you can turn most things into a data frame using as.
It's by no means as bad as most R tables, but clearly it is not good enough to be shared with others. I take the same example she has used, rework some of her code, and then add a few embellishments by me and my colleagues.
In the example below, I set the first column to left-aligned, and the remaining columns are right-aligned. The main reason people love formattable is the formatting of columns. Below, the first column has been changed to grey, color bars have been added to Average, and the last column has been formatted as percentages. Note that the variable names are surrounded by backticks the key above your Tab on English-language keyboardsnot single quotation marks.
In the example above, prior to using formattable I divided the last column byas formattable 's percent function assumes the inputs are decimals. However, we can perform transformations within formattable. In the code below, I divide by and I also color the values as red or green depending on their value. However, IQ cannot really be 0, so arguably the bars are misleading. The fix to this problem is to provide a function that has a more appropriate mapping between the values and the length of the bars.
In the code below, I create a function that returns a 0 for the lowest value 70and a 1 for the highest value In the example below, I've created a heatmap using two shades of green. In this case, I have specified the area using just the columns, but row can also be supplied as well as or in place of col. In this next example, I first format all the cells to be percentages and then apply the color shading to the year columns.
I have to wrap percent in another function, as percent only works on a single column of numbers. You can also write your own functions for controlling formatting. Sometimes it is useful to use arrows to show statistical significance. While formattable is not super flexible in this regard, it can do a good job nonetheless. A problem with this table is that the arrows are to the left of the numbers and are not lined up neatly. The only way I have figured out to avoid this is to put the arrows in a separate column, as shown here:.
The sparklines package can be used to create sparklines :. We can also include them in formattable tables. The way that we do this is by converting the sparkline into text character htmltools::as. I've created all the examples in this post in a live Displayr document, so you can look at the code and play around with it yourself. Click here to view the code and tables discussed in this post. Bert Wassink provided the trick for having a blank column name. My colleague Justin helped me a lot with this post.
View and modify the code in all these examples here! The 4 easy steps that'll make any good researcher proficient at MaxDiff. April 15th, Register now.