Office Hours Megathread

  • Office Hours Megathread

     David updated 1 week, 4 days ago 3 Members · 12 Posts
  • David

    November 4, 2020 at 4:37 pm

    I’ve decided to centralize all office hours discussions here. If you have topics you’d like to discuss during office hours, add them below!

  • David

    November 4, 2020 at 4:38 pm

    On the October 9 office hours session, we discussed parameterized reporting.

    You can find the code from this session here.

    The multireport package that I have developed can be found here.

    The article from the Urban Institute that I referenced throughout is here.

  • David

    November 4, 2020 at 4:39 pm

    On October 23, we discussed a range of topics:

    • Ordering in plots vs ordering in tables (4:27)
    • How to set the column names when making a table (32:00)
    • Custom pagedown templates (see an example here) (37:28)
    • Making parameterized reports (see also this blog post) (40:55)

    The recording of the session can be found below.

    Parameterized Reporting with RMarkdown

  • David

    November 4, 2020 at 4:40 pm

    On November 6, we’ll discuss creating a custom pagedown template. I’ll show one that I’ve developed and talk about how you can customize it for your organization.

    Other topics to discuss? Comment below!

    • clint.thomson

      November 5, 2020 at 2:20 pm

      Hi David, Quick update on the flextable formatting. I ran with your suggestions and produced the code below.

      data <- tibble(

      survey_item = c("Item #1 has to do with food people like to eat", "Item #2 is all about travel and places people like to go", "Item #3 is about movies people like to watch at home and used to see in theatres"),

      percent_program_agree = c(0.78, 0.6, 0.42),

      n_program_agree = c(45, 34, 46)

      ) %>%

      mutate(agree_text = str_c(percent(percent_program_agree),

      " (n=",




      ft1 <- data %>%

      flextable(col_keys = c("survey_item", "code", "agree_text")) %>%

      bg(j = "code",

      i = ~ percent_program_agree >= 0.6,

      bg = "blue") %>%

      bg(j = "code",

      i = ~ percent_program_agree < 0.6,

      bg = "red") %>%

      width(j = "code", width = .05) %>%

      width(j = "agree_text", width = 1) %>%

      width(j = "survey_item", width = 4) %>%

      align(j = c("survey_item", "agree_text"), align = "left", part = "all") %>%

      padding(j = "code", = 1, part = "body")


      What I’d hope to get happening pertains to the newly-created “code” column. Is there any way to put spaces between the color codes between rows? I tried to use padding but to no avail. If there might be some additional time to discuss this, I’d really appreciate it!

      • This reply was modified 3 weeks, 5 days ago by  clint.thomson.
      • David

        November 5, 2020 at 3:18 pm

        Yes! We can definitely discuss this tomorrow!

  • David

    November 6, 2020 at 11:25 am

    Hi folks, I enjoyed today’s session. You can find that below.

    We talked about creating a custom pagedown template. You can see the code that I created here (just look at the pagedown-template.Rmd file and the associated CSS files). Feel free to copy those and adapt.

    We also talked about conditional formatting of columns using the flextable package. I hope that was helpful!

  • David

    November 16, 2020 at 11:22 am

    The next R for the Rest of Us office hours session will be this Friday, November 20 at 10:00am Pacific time. I’ve got two things I want to go over (but please also submit ideas below and I’ll do my best to cover them):

    Heather Lewis, a primary school teacher, has asked how she could use R to produce regular reports on her students’ progress. I’ll take some sample data she has sent me and generate an RMarkdown report, which she will then be able to rerun at any point when she has new data. In addition to providing a refresher on RMarkdown (or an intro if you’re new to it!), I’ll go over a couple concepts that should be helpful even if you don’t work in education: pivoting data from wide to long and using the newish across() function in the dplyr package.

    The second thing I’ll go over is recreating one of the most interesting visualizations I saw in the wake of the US presidential election. This New York Times visualization shows the the swing in county-level votes for president from 2016 to 2020.

    • Paul McElroy

      November 19, 2020 at 9:28 am

      Hi David, this got my attention as I’ve been wondering about how to make the transition from (sometimes data intensive) crystal reports to Markdown in my organisation. There could be anything from dozens to tens of thousands of lines in the output when the crystal report is opened in Excel.

      Is it possible to use Markdown for this volume of data, and is there any way of being able to filter or play around with Markdown output as is easily possible in Excel?

      Would be great to be able to set up reproducible Markdown reports to replace crystal development for each new report.

      I will try to join the call, but I’m 8 hours ahead in Ireland, so 6pm will be giddy kids time so may have to catch up on it after.

      Thanks a million,


      • David

        November 19, 2020 at 4:37 pm

        Hope you can join, Paul! I totally understand giddy kids, though (I’ve got 4 year-old twins). The session will be recorded so you can watch that later.

        I’ll do some future sessions at earlier times to be more accessible for you and others!

      • David

        November 19, 2020 at 4:39 pm

        To your question, I’ll show you how you can export the data from RMarkdown to Excel files for people who want to see those.

  • David

    November 20, 2020 at 2:48 pm

    Here’s our session from today!

    I went over a question from Heather Lewis about how R can help her to improve the efficiency of her workflow. I demonstrated how she could use RMarkdown to automatically generate reports on her students’ progress. In the process of doing this, I demonstrated pivoting data from wide to long in addition to showing how RMarkdown works. The code I generated for this report is here.

    In addition, I demonstrated how to recreate this New York Times visualization that shows the the swing in county-level votes for president from 2016 to 2020. It was a bit more involved than I expected! You can watch this starting at 56:30 and you can see my code here.

Log in to reply.

Original Post
0 of 0 posts June 2018
The R for the Rest of Us community is live! Join regular office hours, ask questions in the forum, and more!