Category Archives: Computery

R adding ‘X.’ to column names

I received some data recently in an Excel file. I opened it in LibreOffice Calc to have a quick look, saved it as a csv, and (tried) to get down to business in R. But all of my column names were an awful mess. Instead of

SPU_Number  SPU_Name  Long_Site  Site

my column names were prepended with X. and appended with a period, like so:

X.SPU_Number.  X.SPU_Name.  X.Long_Site.  X.Site.

I’d used read.csv(), which uses read.table(). This stackoverflow answer clued me in to the fact that R thought there were special characters at the beginning and end of my column names. I reopened the file in LibreOffice Calc and annoying saw absolutely no special characters at the beginning and end of my column names. But when I opened up the file in a normal text editor I saw that my column names had all been single quoted!

To prevent this from happening to you, make sure you check Edit Filter Settings in the Save As dialogue and then make sure both Save cell content as shown and Quote all text cells are unchecked. Or don’t use LibreOffice Calc – Excel won’t screw up your column names like this.

LaTeX only prints first citation

If you’re using a citation style from the harvard package in LaTeX, you might be surprised to find that

\cite{Kremer2012, Campbell1999}

only works on the first citation

(Kremer et al. 2012, ?) .

Unlike some citation styles/packages (notably the default ‘plain’), the harvard package doesn’t allow spaces between citations. To fix this problem just change the example above to

\cite{Kremer2012,Campbell1999}

and your problem is solved!

Tagged ,