Error: <text> when using names() function


I tried to run the code below to rename the column titles of my dataframe. I definitely have the same number of columns as I have names given. Cannot understand why this seems to work sometimes and not work other times. Have tried putting spaces in or switching the ' to a ". Sometimes this makes it work, only for it to fail the next time I run it. Feel like its gaslighting me!!!

names(TestDataModSMD)<- c(‘Article’,’Year’,’Sponsor’,’Species’,’Cry1A’,’OtherCry’,’Order’,’FuncGrp’,’Pollinator’,’Randomised’,’ContMean’,’ExptMean’,’ContN’,’ExptN’,’ContSD’,’ExptSD’,’yi’,’vi’)

The error I get is:

ERROR: <text>

Should mention that I'm using metafor, Rcmdr and xlsx packages.

Very new to R. Working on meta-analysis dissertation to hand in on Monday!!! Any help would be amazing.

Thank you all.


Hi there,

I don't see the actual error you're getting - perhaps you've forgotten to paste it into your post?

Regardless, the function you probably want is colnames (not just names), and it works like so (presuming a dataframe named mydf with 3 columns):

colnames(mydf) <- c("name1", "name2", "name3")

Hope this helps!

1 Like

You have a rogue single quote character at the start of the word "Article". Make sure you only use ASCII single or double quote characters around text strings - and avoid any so-called smart quote characters that are used in some text editors and word-processing software.


Hi thanks for that, see how you were confused by my post - I did paste the error in underneath but not very clear. I replied to my own post to say I'd sorted it, not sure why that didn't come up! Useful to know about colnames any way,