Querying the Patient Opinion API from R

Patient Opinion have a new API out. They are retiring the old API, so you’ll need to transfer over to the new one if you are currently using the old version, but in any case there are a number of advantages to doing so. The biggest one for me is the option to receive results in JSON (or JSONP) rather than XML (although you can still have XML if you want).

Concatenating text nicely with commas and “and”s

Wow, this blog is quiet at the moment. I can’t even remember if I’ve written this anywhere but I had a liver transplant in May and I’ve been repeatedly hospitalised with complications ever since. So work and life are a little slow. I’m hoping to be back to full health in a few weeks. Anyway, I was just writing some Shiny code and I have a dynamic text output consisting of one, two, or many pieces of text which needs to have commas and “and”s added to make natural English, like so:

Working as a coder at a technology company versus working as a coder in other contexts

I was just skimming a book about Python and I found a rather interesting quote: “Programming as a profession is only moderately interesting. It can be a good job, but you could make about the same money and be happier running a fast food joint. You’re much better off using code as your secret weapon in another profession. People who can code in the world of technology companies are a dime a dozen and get no respect.

Open document formats and why we need them

The whole world is moving to open document formats for the obvious reason that in order to read and write documents one shouldn’t need to waste money on Microsoft’s increasingly ungainly Office application when perfectly good free and open source alternatives exist (thinking particularly of the mighty LibreOffice). The UK Government has formally adopted an open standard for all of its documents. Despite this many public bodies in the UK, including the NHS, councils, and many other organisations, continue to use Microsoft’s proprietary formats for documents.

Backing up a remote MySQL database on a remote server using cron

This is more a collection of links, really, than a proper blog post, but I just spent quite a while figuring out how all of these different technologies all fit together to do the job I wanted so if you want to do what it says on the tin of this blog post then you should find it useful. I have a remote server running a MySQL database. I wish to backup this server daily.

Make your own HTML tables in R

I’ve avoid writing HTML tables by hand in R, reasoning that it would be far too complicated. But the problem with using packages like pander and rmarkdown, much as I love those packages, is you can’t fine tune the outputs. So if a colleague asks you to add little extra touches for a report you can’t really do it. So it was a nice surprise to find that it’s actually not that hard.

G++ error compiling on R

I was installing R packages (the httpuv package, but I imagine others would generate the same problem) on my Ubuntu server today and I got a very strange error message: g++: error: Welcome: No such file or directory g++: error: to: No such file or directory g++: error: R!: No such file or directory It was a problem with my .Rprofile.site file. That’s why it looks funny, because R is saying “Welcome to R”, but for some reason this is messing with g++.

Sharing files from host machine on virtualbox

I’ve really started getting into virtual machines recently. Firstly because I like to try different flavours of Linux and constantly reinstalling partitions is starting to get a bit of a drag, especially when it often takes ages to get the graphical desktop to work because of my silly graphics card. Secondly, and more importantly, because I’m finding if you want to do programming, or especially write about programming, you often need a “clean” system or a system set up a particular way to test things and work on multiple things at once.

Single file Shiny app to take GET parameters and return date range input boxes

I’ve spent quite a long time fiddling around with some code for the feedback website for which I am responsible for all the reporting so we can distribute custom URLs to individuals who have specific reports they want to run. We use Shiny to do custom reports, the application lives here, and many of the people who run the reports (our staff in Nottinghamshire Healthcare NHS Trust, mainly) would welcome the ability to have the date range preselected by means of a URL containing GET parameters which they could just click so that the date range is pre-selected.

Producing headings in Word files programmatically using knitr

I love knitr. Sometimes I have to send people documents in Word. It works beautifully except when I want to produce headings programmatically in code using cat(). This is fine in HTML: ``` sapply(headings, function(x){ cat(paste0("<h1>", x, "</h1>")) cat(paste0("<p>", rep("Some text here", 10), "</p>")) }) ``` However, when writing Word .docx files using Rmarkdown the heading tags are not recognised. Well, they’re not printed, so they obviously are recognised, but they don’t work.