Levels of queer representation in media franchises

Warning: spoilers for Star Trek Discovery season 1.

A few days ago, I wrote a short post about “steps” that media franchises take toward queer representation in media. I got a few requests for clarification, so I have expanded it into a table with examples and explanations.

The impulse behind the post was that resistance to representation of queers in media franchises is very predictable, falling into well-known and discrete categories, and that those categories can be ordered from worst to best. I absolutely do not take credit for being the first observer of these dynamics, as many people much smarter than me have commented on them all before. But this is how I see them, on a sort of a continuum.

I originally phrased it in terms of “steps,” although now I don’t think that’s the best way to think about it, so I call them “levels” here. There’s certainly a gradation from 1-7, but of course, not every media franchise goes one by one. Each successive step is better in some sense than the one previous (although you could probably haggle over the ordering in some cases). Levels 1-3 are refusals to represent queers and levels 5-7 are (decreasingly begrudging) attempts at queer representation. Level 4 is, or is not queer representation, depending on your reading of it.

1. Refusal without any attempt at justification

“No queers because writers hate them”

Naked hate for queers, while surprisingly common, is the least interesting case, and nobody needs help identifying it. But most people are more sophisticated because they know they’ll (rightly) get in trouble if they’re openly hateful toward queers, so usually they dress up their hate by progressing to one of the subsequent steps.

I’ve included this one because you do still see it from time to time, and it’s interesting to note how often as a sort of proxy measure for how friendly our culture is to queers.

2. Refusal with some ostensibly principled reason given

“No queers, but it’s for your own good or something”

A justification that is often given for refusal to include queer characters in a story, TV show, movie or whatever is that it would be “pandering,” and that this would be bad somehow. Straight people love to project onto queers a very strong desire that we not be included in something if it is just for the sake of inclusion, and that doing so would be much worse than the default, namely, pretending that queers don’t exist.

This is of course nonsense. The only people who don’t like queers being included just for the sake of including queers are straight people, and this is a feeble excuse for bigotry. But there’s nothing conservative people like better than telling someone No, and having it be For Their Own Good.

3. Refusal, but with a vague promise of future representation

“No queers, but just because we haven’t had a story that demands a queer”

Star Wars is at this point right now. They know there have been calls for queer characters, and they know they can’t just say “No we hate queers,” so they’re kicking the can down the road by saying “not now, but we’re not opposed to the idea,” and trusting we’ll take them at their word when they claim that it’s just “artistic reasons” that have kept them from doing so already.

It’s disingenuous and a double-standard of course. When these writers come up with characters to put into their stories, nobody demands that there be a compelling reason demanded by the plot for why some character is straight. And if they think they can get away with it, they will continue forever to promise to include queers someday, but no sooner than the story absolutely demands it.

4. Strongly implied but ultimately deniable queer representation

“Okay maybe this secondary character is queer? We didn’t say they’re not!”

Harry Potter is an excellent example of this level. JK Rowling famously made Dumbledore gay retroactively after all the book sales were in the bag, and justified it with the condescending Twitter one-liner that gay people just look like … people! So why write them any differently or provide any explicit representation?

The problem with the JK Rowling-type response is the extremely “everything is already perfect so stop complaining” vibe here. The line that we queers are supposed to believe is that the writer is just so progressive that queer representation is unnecessary.

The Star Trek reboot films are also at this level. Everyone got excited about Sulu being gay in Star Trek Beyond (2016), but what we got was 2.5 seconds of Sulu side-hugging some guy, who we’re supposed to take as his civilian husband or partner or something. No kiss. No dialogue. It’s so casual that a straight viewer could miss it entirely or see it and argue that Sulu is meeting his brother or something. And truthfully, there isn’t enough on-screen to settle the matter conclusively.

Reboot Sulu

It is both erasure of queers and it is a not-so-subtle assertion of control that can be read as a disapproval of any queer who isn’t indistinguishable from straights. Also, because this generally flies under their radar, this is a cowardly concession to the sensibilities of outright bigots.

Many Disney villains are also in this category. Ursula from The Little Mermaid (1989) was even based on a drag queen. Straight people love to include queer-coded villains, because they love queer aesthetics, but they refuse to actually provide representation, because they hate queers.

5. Tragic queer representation

“Okay there’s a queer but oops we killed it lol oops”

“Bury your gays” is a well-known and troubling mode of queer representation that has a long history, and it can be summed up as the trope that queers are not allowed a happy ending.

Sometimes, this is done to send a very specific “you get what you deserve, you dirty queers” message. Read Goldfinger if you want a really clear example of that. (Click the Project Gutenberg link and control-F for “Poor little bitch” to read about what happened to Tilly Masterton because she was a capital-L lesbian.)

Goldfinger is an extreme case and most of the time, it’s not an attempt to send an “if you’re gay you deserve a violent death” message. Usually, this happens just because the main character Has To Be Straight, and so if there’s going to be a character who dies, it’s going to be the queer one, and so we end up with a preponderance of media representation in which queers are killed just to raise the stakes for the main characters, just because we’re less important.

We saw this with Lt Stamets in the most recent episode of Star Trek Discovery (S01E09). I thought Discovery was at level 6, but actually it’s looking like it’s here. Maybe they’ll save him? Reserving judgement on this one.

6. Queer representation designed for straight comfort

“Okay there’s a queer but you can’t really tell they’re queer—Super respectable! Very comfortable for straights!”

Often queer representation that is designed for the comfort of straight people is done with the justification that it’s an attempt to “move past bad gay stereotypes.” Again, this is a more subtle example of straight people denying us actual representation and doing it For Our Own Good.

The idea is that there are, according to the straights, way too many flamboyant or promiscuous gay characters perpetuating bad stereotypes and what the world really needs is to see queer people being “good” and that will make all those bigots understand that you can be a good person even if you’re gay. What a progressive message, and who could be upset about that? Right?

The problem is that this has built into it the not-so-subtle assertion of a) control of straight people over queer lives and lifestyles, and b) implied inferiority of queers to straights.

When straights insist that queer representation include only the “good kind” of queer, there’s an implication that there’s a bad kind, and that our acceptance and inclusion hinges on which kind we are. It is tacitly agreeing that queers should be ashamed of who they are and doing their best to hide it.

This often goes hand-in-hand with a denial of the very existence of queer culture. For anything that isn’t literally gay sex, a Respectable-Gays-Only advocate can say “well, that’s not gay per se, so it’s non-homophobic for me to continue to hate it.”

This level also includes “blink and you miss it” queer representation. E.g. the Star Wars 9 lesbians, and Captain America’s Endgame therapy buddy.

7. Actual queer representation

This does actually happen sometimes. Here’s a couple examples:

Pretty much everyone in Sense8 counts. Even the straight dude is not all that straight.

Orphan Black also started at this level. Felix is an excellent example of queer representation. Felix is a nuanced and well-developed character that is undeniably gay, and also unambiguously morally good despite him having a number of the traits that Respectable-Gays-Only advocates would probably categorise as being gay stereotypes. Not only that, but there’s more than one queer character, and this means that they have a tragic gay character proportion of less than 100%, which is more than I can say for Star Trek Discovery.

How to get any medical journal into your RSS reader even if they don’t provide an RSS feed

What is RSS?

For the non-initiate, RSS is a very useful protocol that is used all over the web. You can think of it as a way of separating a stream of content from the website where it’s normally viewed. Nearly every blog has an RSS feed, as do news sources, web comics, and even academic journals. Podcasts are like a specialised version of RSS for audio files only.

What makes RSS great is that I can take all the RSS links from all the news sites, blogs, webcomics and journals that I’m interested in and put them together into a single aggregator (I use Feedly). In this way, I don’t have to be constantly checking all these websites to see if there’s new stuff posted.

But what about medical journals that don’t provide RSS?

Unfortunately, there are some medical journals that do not have an RSS feed. For example, the JNCI (the Journal of the National Cancer Institute) does not have one. (If I’m wrong, please put the link in the comments.) So if I want to know what’s been published recently in the JNCI, I have to visit their site, or look on their Twitter. This is annoying, since the whole point of RSS is to have all the content you want to consume (or as much of it as possible) in the same place.

Pubmed allows users to save any search as RSS feeds

Pubmed provides a wonderful and open, standards-compliant service, but almost no one seems to know about it! This is great for people who are actively researching a subject, and also for people who just want to keep up with a particular journal or subject area.

Some of you have probably figured out where I’m going with this by now, but if you haven’t, I’ll spell it out. Let’s continue with the example of JNCI.

How to put new articles from any journal into Feedly

This assumes you already have an account on Feedly, but you can do this with any RSS reader, of course.

  1. Visit Pubmed in your browser
  2. Click “Advanced” under the search field
  3. Under “Builder,” click “All fields” and choose “Journal”
  4. In the text field beside the box where you selected “Journal,” enter the name of the journal you’re interested in (it will autocomplete, if you have done this correctly, you should see something like “Journal of the National Cancer Institute”[Journal] in the uneditable text field at the top)
  5. Click “Search”
  6. Under the search field at the top of the page, click the “Create RSS” link
  7. Choose how far back you want your search to go (I chose 20)
  8. Click the “Create RSS” button
  9. Right-click the orange “XML” button and click “Copy link”
  10. Go to Feedly, and paste the link into the “Search” field at the top right
  11. There should be one result, click “Follow” and choose which collection you want to keep it in

You’re done! Now whenever Pubmed indexes a new entry for that journal, it will appear in your RSS reader!

You can also make RSS feeds for any search you want on Pubmed

Of course, you may not be interested in everything a journal has to say, so you can refine the search to only include “breast cancer” or you can drop the journal identity part of the search entirely. The world is your oyster!

Introducing Serlingbot

My boyfriend and I were watching an episode of The Twilight Zone this week, in which a newly-minted revolutionary dictator is told by a departing member of the overthrown government that a particular mirror would show him his assassins. Of course, this leads him to kill his closest friends.

Sorry, should have said “spoilers” or something. Although really, you’ve had 56 years to see this episode. If you’re not caught up, that’s on you.

At the end of the episode, my first thought was: Trump would probably have fallen for that line too.

Inspired by that episode and of course by a Scottish newspaper immediately prior to Trump’s inauguration, I had an idea: A Twitter bot that downloads photos tweeted by the White House, turns them greyscale, overlays them with Rod Serling and tweets them again.

On my first Google search, I found a transparent PNG of Rod Serling. The Internet had also prepared a repository of json-formatted Rod Serling monologues. All I had to do was find a PHP library to connect to the Twitter API, and I was good to go!

You can follow @serlingbot on Twitter, and it will regularly send you photos from a few selected Twitter accounts that have been Serling-ed.

But that’s not all!

If you tweet a photo to @serling on Twitter, it will reply to you—with your photo Serling-ed.

And if you don’t have Twitter, I have made a non-Twitter web version of Serlingbot, where you can enter a link to an image on the web, and it will Serling your photo for your own private use.

I like to think that Rod Serling himself would have appreciated the idea of being resurrected as a post-apocalyptic robot, doomed to condemn a totalitarian government from beyond the grave. It’s something that might have happened … in the Twilight Zone.

Media literacy for the Trump era

I have compiled and explained a list of four five common fallacies that I have noticed while consuming news media in the age of Trump. These aren’t new since Trump was made president, but I feel like they are exacerbated by the current administration. They’re meant to be taken in the spirit of the “laws of the internet” that dictate “if you can imagine it, there’s porn of it,” or “any sufficiently long internet argument will eventually invoke Hitler,” etc.

The law of imputed 12 dimensional chess

No matter how demonstrably stupid Trump’s action, it will always be depicted by some as a part of an inscrutable master plan.

Every time Trump does or says something bad, it will be followed up by a series of hot takes, tweets or op-ed pieces in which we all try to guess what his real goal is. E.g. “He’s banned Muslims from entering the United States. But what is his endgame here? What is he trying to distract us from?”

Muslims being banned is the real crisis. Just because us white people aren’t directly affected doesn’t mean that the real evil is coming later. It’s not a feint to make us look the wrong way. That was it. This is not a drill. Real people are being hurt.

I think there’s a few reasons that this fallacy occurs so often. It’s hard to admit, but Trump isn’t a genius who beat the political system by being some calculating mastermind. That would be easier to take in some ways. (He’s profoundly stupid,1 but he’s wealthy and the system is just not set up to protect us from people like him.) As best I can guess, the “12 dimensional chess” theories are appealing due to: 1. simple self-centredness and latent racism (i.e. “It’s bad, but it doesn’t affect me, so the badness must be something else”), 2. a desire to avoid admitting that the left was beaten by a blasted fool or 3. a McCarthy-like impulse to cast the villain as omnipotent.2 Take your pick.

The law of sacrificing marginalised communities

Marginalised communities will be the ones most negatively affected by Trump’s policies, but they will also be the ones blamed for it, directly or indirectly.

Here is an example of what I mean: The February 2017 cover of The Economist3 features the profiles of Trump and Putin facing each other. Trump is wearing lipstick and there’s a kiss mark on Putin’s cheek. The implication is that Trump and Putin are gay.

The LGBTQ+ community has been betrayed by Trump’s recent executive order that rolled back protections for trans people.4 Gay men are now being turned back at the US border after being interrogated and humiliated over the private contents of their phones.5 Things are bad and I don’t know if they’re going to get better.

But of course, the joke that’s currently in vogue is that Trump is gay. (Ooh! Burn!)

Now, I get it. I’ve made jokes like this in the past, but I’ve had a change of heart on the subject. It would certainly bruise the egos of Trump and Putin to be called gay, but then they’re not going to be reading my Twitter feed. Other people will read my messages though, and they will be getting the message that it’s okay to use “gay” as an insult, or to throw marginalised communities under the bus to make a cheap shot at a world leader who honestly doesn’t care.

This is just one example of a marginalised community that’s being indirectly blamed for their own oppression, but I guarantee you that for every similar issue that comes up, there will be self-styled “centrists” or “moderates” who tell the more progressive elements of society that it’s “their own damn fault” for getting uppity and demanding something that the mainstream has had all along. You’ll often see this happen along with the phrase “This is why Trump won,” blaming progressives, women, LGBTQ+, whatever for the rise of Trump.

Watch for it. Any protest or statement with a progressive bent will be met by an opportunistic “centrist” who wants to shut you up by telling you that they agree with your general goal, but that you must be nicer about it and accept a glacially slow pace of progress, and that anything other than that “is why Trump won.”

The law of conservative victimhood

No matter how empowered conservatives become, they will always find a way to make their own victimhood the focus.

This is also an impulse I can sympathise with. I grew up in a super-conservative community, and so I was taught from a young age to believe that it is Christians and conservative Christians especially who are a marginalised minority in Canada. I was taught—and I fully believed—that Christianity was persecuted, and indeed if you define Christian orthodoxy narrowly enough, one can certainly maintain that delusion for quite some time. So I understand where they’re coming from.

But it’s still stupid.

Conservatives always have the upper hand. They aren’t a persecuted minority. That’s just what conservatism is—it’s the political inclination to support the status quo. It’s the people who have power working to support the institutions that got them there. The highest office in the United States has just been awarded to a conservative. The House and the Senate both have Republican majorities. Conservatives are not victims. Not in any sense. In fact, they hold a disproportionately large amount of power over the machinery of government.

And yet, conservatives will defend their victimhood as if that were their very essence.

If there comes a day when there is a shortage of foreign workers to pick the vegetables that Americans want to eat, the tragic hero of the story when it is told will be the poor hard-working American who can’t afford how expensive vegetables have become, and not the foreign workers who were deported. Count on it. Or if a queer person is beaten, the biggest controversy will be whether or not it’s fair to label the aggressor as “homophobic.” And we’re already seeing the beginning of what I expect will be a steady stream of op-ed pieces about how people who supported Trump are the real victims of liberals who are being big meanies about the fact that their choice for President is a fascist.6

It shouldn’t have to be said, but if you supported a fascist by voting for him, and that fascist’s policies mean that your friend is the victim of hate somehow, you should have the perspective to understand that you are not the victim in this situation. You are closer to being the aggressor.

This dynamic is probably strongest along racial lines, but you also see it along the queer-straight axis as well. (E.g. “They excluded police officers from Pride? That’s the greatest injustice in the history of the queer rights struggle!”)

C.f. The “Liberal bubble”

The law of false centrism

No matter how far the political centre is pulled to the right by extremists, anyone who questions “centrism” by advocating policies to the left of where the new political centre has been pulled will be dismissed as insane.

To make a facetious example, if Trump is saying that we need death camps for Muslims at every border crossing and his opponents are saying we shouldn’t have any, the fallacy of centrism would be to say that we only need death camps at certain major border crossings.

This one makes me worried for the future because the main message of the Democratic party from 2016 seems to have been, “If you’re politically to the left of Clinton, we don’t want or need your votes, you dirty Bernie bro. You’re just as bad as Trump.” This message only leads to political victories if everyone is really, really excited about being a political moderate. And only if they’re also okay with the political “centre” being shifted to the right.

From a Canadian perspective, it’s very easy to see how the American political spectrum is shifted. The policies of the centre-right party in Canada (The Liberal Party) would be considered so far left wing in America as to be absolutely unthinkable.

The law of imperfect protests

No matter how despicable the thing that is being protested, if the protest can be criticized—in any way—”moderates” will focus on that.

This mostly goes for student protests, but you see it in other contexts. I’ve seen it a dozen times if I’ve seen it once, and sometimes from people that I would otherwise consider to be very intelligent. Usually you see it shortly after a protest, and often it starts with a somewhat strained observation that the protest is “so ironic.”

E.g. “It’s so ironic,” said the moderate, “They claim to be against death camps, and yet there’s a small amount of litter left after the protest”

This example is really exaggerated, although who knows, we may get there. The fallacy I’m trying to point out is that the violence of white nationalism or fascism or being an outright peodphile apologist is nowhere near the level of violence of a stupid student protester who breaks a window or something while protesting against it. These are absolutely not equivalent, and a protest that doesn’t go 100% perfectly shouldn’t be a reason to throw up one’s hands and say, “Well, I can’t support these protesters because they broke a window. Their position looks just as violent as the white nationalists’.”

“Moderates” love to point out The Irony of this situation, and they also love to ring their hands over how the poor fascist just wanted to speak, and how this protest has somehow damaged Free Expression itself (as if protests weren’t also speech as well).

Like the other fallacies, this is not particular to the Trump era, but it seems much worse now. Watch for it and the others, as well as their themes and variations.

Edit (2017 March 6: Added “The law of imperfect protests”)


  1. https://twitter.com/Kris_Sacrebleu/status/832325609132953604
  2. https://theintercept.com/2017/02/23/the-increasingly-unhinged-russia-rhetoric-comes-from-a-long-standing-u-s-playbook/
  3. http://www.economist.com/printedition/covers/2017-02-09/ap-e-eu-la-me-na-uk
  4. https://www.nytimes.com/2017/02/22/us/politics/devos-sessions-transgender-students-rights.html
  5. http://www.huffingtonpost.ca/2017/02/22/canadian-man-customs-gay-app_n_14928858.html
  6. https://www.nytimes.com/2017/02/18/opinion/sunday/are-liberals-helping-trump.html

Are pronouns up for debate or not?

There’s been a lot of ink spilled recently about the use of pronouns and preferred names in academia. At U of T, one professor in particular is kicking up a fuss about having been asked to use students’ preferred names and pronouns. A CBC editorial on the subject by Neil Macdonald recently provided an entertaining example of a baby boomer throwing a sputtering temper tantrum over the fact that he’s being asked to think about other people.

I could begin demanding that my colleagues refer to me as “blort” or “zonge” with the expectation that they would respectfully begin doing so.

(Imagine wanting to be treated with respect! Hilarious! Also, for the record, the singular “they” is not some newfangled invention of “those damn SJW’s.” There’s at least one example of it in Shakespeare. See A Comedy of Errors, Act IV, Scene 3.)

It’s almost not worth saying that this is a generational thing, and when the boomers have passed on, their faux indignation over being asked to be a decent human being will die with them. In a couple decades, this debate will seem as weird to us as a prof who insists that freedom of expression means that he has the right to use the n-word to refer to students who are people of colour.

But let’s take the question of whether we should debate another person’s pronouns at face value, just for fun. Academia is supposed to be an anything-goes bare-knuckle cage-match of ideas, right? Are there legitimate reasons why we might not want to have a debate over pronouns?

I’ve come up with two.

Intellectual honesty

Let’s start with the example of smoking and lung cancer. I’ll get back to the debate at hand, I promise.

Smoking causes lung cancer. This is a fact.

Yes it’s a probabilistic thing; yes, it’s true that not all smokers get lung cancer; yes, it’s true that not all people with lung cancer smoked. But the causal link between smoking and lung cancer is so well established that it is now beyond doubt.

If, in 1950, there was a formal debate at McGill called “Does smoking cause lung cancer?”, that might have been an appropriate debate to have. There was genuine uncertainty over the issue at the time.

However, if I saw a poster on campus today in 2016 for a debate with the same title, I would take it to be a major failing in terms of either scientific judgement or intellectual honesty on the part of the organisers. I would question either their motives or their competency. For a person who wants an answer to the question of whether smoking causes lung cancer, the appropriate response is to point them toward the library, where there are reams of good data on the subject. A debate would not be appropriate.

The reason for this is that a formal public debate presupposes a certain equipoise between the sides being debated. Just framing certain issues as needing to be discussed by academics in the manner of a debate can be dishonest, like in the smoking/lung cancer debate example.

And so sometimes when a person says that something is “not a matter of debate,” it’s not because that the person is some insecure authority whose policies cannot bear scrutiny and they wish to stifle dissent by barring discussion. Sometimes when a person says that something is “not a matter of debate,” they just mean that it would be irresponsible and dishonest to use the machinery of academic “debate” to introduce unwarranted uncertainty where the issue has already legitimately been settled.

As academics, of course we need to be ready to defend any position we take. If there is anywhere that debates should happen over difficult, offensive or extremely technical subjects, it’s within a university. And yet, not all debates are intellectually honest ones to have. Sometimes when a person says, “Let me play devil’s advocate,” the correct response is, “The devil has enough advocates.”

Yelling ‘fire’ in a crowded theatre

Not all speech is benign. The famous example is that if you falsely yell “fire” in a crowded theatre, you could kill people.

The same goes for other forms of speech, including academic or political “debates.” After Harper dredged up the niqab debate in the 2015 election, there were violent physical attacks on Muslims in Montreal. The Brexit and Trump campaigns also both arguably brought about spikes in hate crimes in the UK and the US. If you have debates like, “Should we ban Muslims from our country?” those can—and we have seen recently that they do—incite violence against Muslims.

Other sorts of speech can cause harm even more directly. Let’s imagine the example of a trans student in a small class who doesn’t want to be outed as trans to her peers. Imagine that the student goes to the teacher on the first day of class and says, “I know the class list has my name as ‘John,’ but I go by ‘Jane,’ and I’d like you to use ‘she/her’ when referring to me.”

Let’s further imagine that the professor is of the type who refuses to respect a student’s preferred name and pronouns on principle. Just by exercising their “right to freedom of expression,” this professor could out the student to their peers against the student’s will, which could directly put them at risk of harm. This student might be threatened or harmed, but even if the student is lucky and nothing bad happens, she might just feel threatened by this behaviour, which is a harm in itself.

Part of the problem is that discussions that can cause harm or risk of harm to others are often initiated by people who don’t bear any of that risk themselves. So for example, when Harper decided to “have a debate” on the niqab for his own narrow political ends, he did so knowing that he would never be the target of the anti-Muslim violence that followed. Similarly, a cis prof who refuses to use preferred names and pronouns will never be on the receiving end of violence against trans people, and they aren’t even in a good place to evaluate the level of risk that they may be imposing on other people against their will.

The prof at U of T wants to paint himself as the brave intellectual, bucking the orthodoxy and asking questions that no one else has the courage to ask, while his opponents won’t even meet him for an honest discussion. All I see is a guy who doesn’t have any skin in the game, who can afford to debate the level of respect owed to other humans because it will never affect him personally.

What does it mean when someone says their pronouns aren’t up for debate, then?

When a person says their pronouns “aren’t up for debate,” they are not saying that there is no defense for the position they’re taking. There is a field of study that has considered, among other things, the question of pronouns and preferred names. In a lot of academic institutions, it’s called “Gender Studies.” You’ve probably made fun of it. But the fact that you’re ignorant of an entire academic discipline and decades worth of research doesn’t mean that there is a genuine question to be considered. It might just mean that you need to go to the library.

And when a person says their pronouns “aren’t up for debate,” they might mean that what seems like an abstract, academic discussion to you could mean harm or the risk of harm to them. They’re not saying, “My position cannot stand up to criticism.” They’re saying, “I don’t want to be a casualty of this discussion.”


Everything should be open for debate—in principle—but not all debates come from a place of intellectual honesty, and not all debates are benign.

A gift of the fae folk, I assume?

What is this thing?
What is this thing?

I tried to go to the Snowden talk at McGill a couple weeks ago. The lineup was too huge for us to get in, so we went to Thomson House, the McGill grad students’ pub, and hooked a laptop into a TV there to watch.

Seriously, what?
Seriously, what?

On the way back, in a pile of stones upturned by the construction between the Leacock and Brown buildings on the McGill campus, I found a little medallion marked with strange symbols. It has a pentagram on one side and Death on the other.

I don’t know what to make of it. I assume it was left for me by the fairy folk, and that it’s a good omen?

How to get R to parse the <study_design> field from clinicaltrials.gov XML files

Clinicaltrials.gov helpfully provides a facility for downloading machine-readable XML files of its data. Here’s an example of a zipped file of 10 clinicaltrials.gov XML files.

Unfortunately, a big zipped folder of XML files is not that helpful. Even after parsing a whole bunch of trials into a single data frame in R, there are a few fields that are written in the least useful format ever. For example, the <study_design> field usually looks something like this:

Allocation: Non-Randomized, Endpoint Classification: Safety Study, Intervention Model: Single Group Assignment, Masking: Open Label, Primary Purpose: Treatment

So, I wrote a little R script to help us all out. Do a search on clinicaltrials.gov, then save the unzipped search result in a new directory called search_result/ in your ~/Downloads/ folder. The following script will parse through each XML file in that directory, putting each one in a new data frame called “trials”, then it will explode the <study_design> field into individual columns.

So for example, based on the example field above, it would create new columns called “Allocation”, “Endpoint_Classification”, “Intervention_Model”, “Masking”, and “Primary_Purpose”, populated with the corresponding data.

require ("XML")
require ("plyr")

# Change path as necessary
path = "~/Downloads/search_result/"

xml_file_names <- dir(path, pattern = ".xml")

counter <- 1

# Makes data frame by looping through every XML file in the specified directory
for ( xml_file_name in xml_file_names ) {
  xmlfile <- xmlTreeParse(xml_file_name)
  xmltop <- xmlRoot(xmlfile)
  data <- xmlSApply(xmltop, function(x) xmlSApply(x, xmlValue))
  if ( counter == 1 ) {
    trials <- data.frame(t(data), row.names = NULL)
  } else {
    newrow <- data.frame(t(data), row.names = NULL)
    trials <- rbind.fill (trials, newrow)
  # This will be good for very large sets of XML files
  print (
      " processed (",
      format(100 * counter / length(xml_file_names), digits = 2),
      "% complete)"
  counter <- counter + 1

# Data frame has been constructed. Comment out the following two loops
# (until the "un-cluttering" part) in the case that you are not interested
# in exploding the <study_design> column.

columns = vector();

for ( stu_des in trials$study_design ) {
  # splits by commas NOT in parentheses
  for (pair in strsplit( stu_des, ", *(?![^()]*\\))", perl=TRUE)) {
    newcol <- substr( pair, 0, regexpr(':', pair) - 1 )
    columns <- c(columns, newcol)

for ( newcol in unique(columns) ) {
  # get rid of spaces and special characters
  newcol <- gsub('([[:punct:]])|\\s+','_', newcol)
  if (newcol != "") {
    # add the new column
    trials[,newcol] <- NA
    i <- 1
    for ( stu_des2 in trials$study_design ) {
      for (pairs in strsplit( stu_des2, ", *(?![^()]*\\))", perl=TRUE)) {
        for (pair in pairs) {
          if ( gsub('([[:punct:]])|\\s+','_', substr( pair, 0, regexpr(':', pair) - 1 )) == newcol ) {
            trials[i, ncol(trials)] <- substr( pair, regexpr(':', pair) + 2, 100000 )
      i <- i+1

# Un-clutter the working environment

remove (i)
remove (counter)
remove (data)
remove (newcol)
remove (newrow)
remove (columns)
remove (pair)
remove (pairs)
remove (stu_des)
remove (stu_des2)
remove (xml_file_name)
remove (xml_file_names)
remove (xmlfile)
remove (xmltop)

# Get nice NCT id's

get_nct_id <- function ( row_id_info ) {
  return (unlist (row_id_info) ["nct_id"])

trials$nct_id <- lapply(trials$id_info, function(x) get_nct_id (x))

# Clean up enrolment field

trials$enrollment[trials$enrollment == "NULL"] <- NA

trials$enrollment <- as.numeric(trials$enrollment)

Useful references:

  • https://www.r-bloggers.com/r-and-the-web-for-beginners-part-ii-xml-in-r/
  • http://stackoverflow.com/questions/3402371/combine-two-data-frames-by-rows-rbind-when-they-have-different-sets-of-columns
  • http://stackoverflow.com/questions/21105360/regex-find-comma-not-inside-quotes

How to open XML files in LibreOffice from the WHO ICTRP

The WHO provides a “Search Portal” for the International Clinical Trials Registry Platform at the following address:


Try it out! Do a search for “ixabepilone AND endometrial” for example. This will return a table of 4 clinical trials (or it did on 2016 Sept 21) with a red button at the top right that says “Export results to XML.” If you click this button (then “I agree,” then “Export all trials to XML”) your browser will save an XML file with the results in it.

Using LibreOffice to parse these data

LibreOffice Calc XML import
LibreOffice Calc XML import

LibreOffice has a great tool for importing XML information, like the sort you just downloaded from the WHO database.

Open LibreOffice Calc, then click on Data > XML Source …

But there’s a problem

If you navigate to where your browser saved the XML file and choose it as the “Source File,” you’ll have a problem. The “Map to Document” field won’t be populated by elements from the XML file as expected.

I reported the bug to the LibreOffice people, but in the meantime …

Here’s a workaround

Open up the XML file in a plain text editor (Notepad, Atom, Scratch, etc.).

The first line will look like this:

<?xml version=’1.0′ encoding=’UTF-8′ ?><Trials_downloaded_from_ICTRP>

Just change that line so that it looks like this:

<?xml version=”1.0″ encoding=”UTF-8″ ?><Trials_downloaded_from_ICTRP>

The only difference here is that the single quotes are replaced with double quotes. LibreOffice will read the file as expected now!

Click where it says “Trial” under “Trials_downloaded_from_ICTRP” in the “Map to Document” field, choose A1 as the “Mapped cell,” and click the Import button!

You can now read through WHO ICTRP files on LibreOffice Calc.

Unboxing elementary OS Loki

On Friday, the latest version of elementary OS was released: version 0.4, Loki. I’ve been using elementary since Freya public beta 2, and it’s been a great general purpose working machine.

So I backed up all my files, downloaded the disc image and re-formatted my computer. Here are my impressions and notes:

  • The installer worked really well. No surprises. It was straightforward, fast, and it worked on the first time. I just restarted my computer with the USB installer drive in it, and it worked. On the first try.
  • For reference, to install the previous version, Freya, I had to use another computer to download wifi drivers so that I could get the computer on the internet. It took a few tries. Not this time!
  • Also, the previous version had a really hard time with rebooting. I had to fiddle around in GRUB settings to make it work. This time it worked right out of the box.
  • Loki is designed to be simple. This means that certain features, like adding software repositories, is disabled. Hence, right away I installed: software-properties-common, gdebi and elementary-tweaks, of course.
    • gdebi was necessary to install Atom.io, R Studio, Vocal, etc.
    • Single-click to open files by default in the file manager? Really?
  • I needed to follow the instructions on the following page to get R running: http://sites.psu.edu/theubunturblog/installing-r-in-ubuntu/
  • I needed to install Dropbox from here: https://github.com/zant95/elementary-dropbox
  • This version of Loki is based on Ubuntu 16.04 rather than 14.04, which fixed a lot of the problems that I forgot I had. For example, this allowed me to upgrade to the newest version of LibreOffice. LibreOffice was working mostly fine before, except for a weird graphical glitch with the Zotero plugin (the buttons’ colours were inverted).
  • Now that I’m on the topic, installing LibreOffice from the AppCenter didn’t work. I had to un-install and then install from the command line. That was weird.
  • The system tray is much better now. There were a few apps that just never appeared up there despite my best efforts to fix them.
  • I don’t actually care for the new “AppCenter” that comes with Loki very much. Some of the software that’s in there doesn’t “just work.” (LibreOffice for example didn’t work until I installed it using apt-get in the Terminal.)
  • Adobe Digital Editions still works perfectly through Wine, so I can still get all my library books on my Kobo that way.
  • I installed Deja Dup from the command line, and then followed these instructions to hook it up to the file manager: http://elementaryos.stackexchange.com/questions/1741/how-to-integrate-files-with-dejadup
  • The Music app is very iTunes-like. And by that I mean that it is what iTunes used to be like before it became bloated and unusable. It’s a simple, single-purpose app that opens from a cold start in less than a second on my computer. There’s no store. It doesn’t sync my phone. All it does is index the music files in my ~/Music folder, and allows me to play them.
  • Actually, come to think of it, that’s what I like about elementary OS as a whole. It’s Mac-like, but without a lot of the really annoying bloaty stuff that makes it hard to actually get work done on a Mac.
    • How many times do I have to tell my computer, “No, I don’t have or want an Apple ID?”
    • “No, I don’t want this update to GarageBand.” Stop asking me.


This is the best ever!

We're calling it "Two Queens Honey"
We assembled our apiary with … Pride (haha it’s a gay joke)

I am the most hipster now

I am unreasonably excited about this and have been for months.

As of last Sunday, I am the most hipster ever. This has been a project that’s a long time coming. I’m sure that my colleagues are tired of hearing me talking about it: A few weeks back we bought an apiary, assembled it, painted the top like a Pride flag, and then on the 29th, we went to pick up our bees!

On the night that they arrived, it rained fairly intensely, and hearing this, Alain and I ran to the back porch to check on them, like worried parents.

They were okay.

This brings me one step closer to my dream of being the undisputed king of the hipsters by walking up and down the Plateau wearing an ironic beard of bees.

Ten Thousand Babies
Ten Thousand Babies

We now have ten thousand babies

This is a lot of bees. They came on 5 wooden “frames” with a sort of waxy backing that’s reinforced with wire, on which the bees make their honeycomb and fill it with wax or pollen or eggs. We do have a friend who knows what he’s doing, and with his help, we transferred the 5 frames into a much bigger 8-frame box.

To do so, we had to pick up each frame by hand and slowly transfer it over. You’d think that the bees would start getting stabby at that point, but they really didn’t care. At all. Honeybees are super-chill. I had probably a couple dozen bees going over my bare hands while moving them over to their new home, and none of us got stung. Alain moved the frame that had the queen on it.


Our neighbour was in the back yard that morning. She almost certainly saw the giant swarm of bees while we were moving them from one box to another. No comment yet. There, of course, is no longer a giant swarm. The picture attached above makes it seem like there’s thousands of bees flying around everywhere, but they were just excited in that picture because they were still moving over from their old box to the new one.

Unless you’re actively looking for bees in our back yard, you’d never know that there’s an apiary with 10-80 k bees in it right there. There’s always a few at the entrance, but you can stand even a metre away and bee totally unaware that our little ladies are there, doing their thing.

We're so cute!
Two Queens Honey!

Among the problems I never thought I’d have, “too much honey” used to bee one of them

By the way, get used to the “bee” puns. They’re going to bee awful. I will also point them all out and explain the jokes as we go along. Puns are the highest form of humour after all, and jokes are better when you explain them.

We might have as much as 23 kg of honey from this season, and so we’ve decided to sell it along with the wax. We’re calling our product “Two Queens Honey.” (That one is a gay joke, and also a bee pun!) The flavour of honey is determined by the plants that the bees feed on, so I wanted to take up our lawn and put in nothing but hot peppers, just to see if we could get honey with a bit of a … sting.

My idea was vetoed. Alas.

Honestly, I’m amazed that this idea wasn’t shot down earlier. To quote Alain,”I never would have done this if we weren’t together,” or as my ex-wife put it, “This is another reason why you and Alain are a much better match.”

We are planning on taking a beer-brewing course later in the summer, so there may be Two Queens Honeybeers coming. More on this story as it develops.