Wednesday, February 27, 2019

On a Slow Train to Nowhere

I came across a story on CNN about folks who had been trapped on an Amtrak train traveling from Seattle to Los Angeles. They had been stranded just south of Eugene due to snow for over 30 hours when I first saw the story.

That particular train was one I had taken several times when I was living in Eugene. Even on a good day, the trip from Eugene to Salinas (where I was usually headed) was about 18 hours. It is a very scenic route, but I'm not sure I'd want to spend more than a day on it.

That said, one thing that the article glossed over is that part of the issue is the fact that Amtrak trains do not have the right of way on this route. Amtrak owns the trains, but not the tracks that those trains run on. Because passenger rail is generally not as profitable as freight rail, passenger trains end up playing second fiddle once they get stuck.

It would be a mistake to think that Amtrak is problematic because it is government run (though there are certainly issues with that being the case). The private sector solution would be to get rid of passenger rail altogether.

Infrastructure anyone?


Tuesday, February 12, 2019

Table References in R Markdown to PDF

This is just a quick post for my own sanity. I spent a fairly decent amount of time trying to figure out how to reference tables in an RMarkdown document when outputting to PDF. For the record, I'm loading the booktabs and float packages in LaTeX (via the YAML header) and kable in R.

The trick that seemed to work is to put the LaTeX label as part of the kable argument: caption="\\label{tab:tabname}Caption text". The table can then be referred to in the text with \ref{tab:tabname}.

I'm sure that there are more elegant ways than this, but this seemed to get me what I needed for now.

Tuesday, January 29, 2019

Would You Like an Update With That Update?

Do you ever have one of those days when a simple task takes forever? You know, those days when you find yourself shaving a yak instead of getting work done?

That happened to me today. I was trying to track down a bit of missing data in an analysis I was doing. In the process of doing that, I came across the Data Explorer package for R, which seemed like it could be useful. (Definitely check it out if you are an R user.) However, my version of R was a little out of date, so I decided to do a, ahem, "quick" upgrade so that I could install the package.

Of course, if I'm going to update R I might as well update RStudio, right?

After updating R and RStudio, I soon realized that, for whatever reason, I could no longer knit to PDF. I spent a decent amount of time trying to troubleshoot the problem, including trying to update packages in MikTex, which was the LaTeX engine I was using. After going down a lot of rabbit holes, I did some Googling and realized that I wasn't the only one having this problem.

Long story short, it seemed like switching to tinytex was the preferred solution (which also meant spending time searching for a non-existent "uninstall" file for MikTeX). Eventually, I got everything back in working order (fingers crossed), but that was not before I had spent the better part of a few hours on my "quick" upgrade.

I guess the moral of the story (according to the bumper sticker) is, "If it ain't broke, fix it 'til it is."



Friday, January 25, 2019

Rocky Mountain Strike

So, another week, another strike. Just as the LAUSD teachers seem to have reached an agreement to end their strike, teachers in Denver, Colorado have voted to strike as early as January 28 according to news reports. Low compensation seems to be one of the primary reasons, as teachers complain that they are not earning a living wage given the cost of housing in the area.

Wednesday, January 16, 2019

New Year, New Strike

As of today (January 15, 2019), teachers from the Los Angeles Unified School District (LAUSD) have been on strike for two days. Although wages have been one of the demands, the bigger issue is the perceived lack of investment in education over the past several years and decades.

I can't recall any politician who has claimed that education is NOT a priority when campaigning. Funny how that passion never seems to make it past the swearing in ceremony. 

Thursday, January 10, 2019

Apparently, Failure is an Option

At one point last year, I noted in awe that Andrew Gelman's blog had entries scheduled for publication months in advance. I stated that my criteria for success would be a much more modest "at least one post within the past two weeks" (or something similar).

I guess even that was being optimistic.

I won't make any grand New Year's resolutions about posting frequency, but I do hope to be a little more consistent this time around.

Happy New Year!

Wednesday, December 12, 2018

Rendering bupaR Process Maps in RMarkdown PDF

I've been playing around with a very nice R package called bupaR, which stands for "Business Process Analysis in R." It is actually a suite of packages that support different parts of the process mining workflow.  For those unfamiliar with the term, process mining is a method of extracting information from event logs. It is a type of data mining, but with a temporal aspect as information moves through a business process (think: booking a flight, approving a purchase order, etc.)

In my case, I was trying to do some process mining on IT help desk-type ticketing system. Because this was some initial exploration, I was using RStudio to create and RMarkdown document in which I could keep track of what I was doing and present some output from the analysis.

The bupaR ecosystem has a package called processmappeR which can create process maps (kind of like a flow chart) from an event log. When knitting the document to HTML, the maps were coming out beautifully, as were the various other figures I was generating. However, when I tried to knit to PDF to share the document with a colleague, I noticed that all of the process maps were missing without a trace.

Long story short, the processmappeR package seems to rely on network graph diagrams that were intended for use in a viewer or Shiny app. After lots of Googling, I came across a thread in the DiagrammeR GitHub repository that had an answer and a link to a more complete discussion by Yihui, the creator of bookdown (https://bookdown.org/yihui/bookdown/html-widgets.html).

The basic idea is to install the webshot package, then use that package to install phantomJS.

install.packages("webshot")
webshot::install_phantomjs()

This essentially takes a screen shot of the graphic that you are trying to render as part of the knitting process. I'm still working on tweaking the resulting images, but the process worked like magic and I now have all of my process maps as part of my PDF document. Awesome!