Converting Gene Symbol to Ensembl ID in R I'm trying to convert ~20,000 different human gene symbols to ensembl IDs. I've been trying to use biomaRt to do this, but continue getting the following error 

getBM( attributes=c("ensembl_gene_id") , filters= "mgi_symbol"  ,mart=ensembl)
Error in martCheck(mart) : 
  No dataset selected, please select a dataset first.  You can see the available datasets by using the listDatasets function see ?listDatasets for more information.  Then you should create the Mart object by using the useMart function.  See ?useMart for more information


Is there a different format I should be using for this? I tried using BioConductor's description of how to use getBM but am a R novice and confused as to how to set this up to convert gene symbols into ensemble IDs.
You can use the standard annotation package for humans (you can also use biomaRt, but it can be more confusing, see below):

library("org.Hs.eg.db") # remember to install it if you don't have it already
symbols &lt;- mapIds(org.Hs.eg.db, keys = ensemblsIDS, keytype = "ENSEMBL", column="SYMBOL")


The ensemblsIDS should be a character vector: c("ENSG001", "ENSG002", ..)

The solution with biomaRt:

library("biomaRt")
ensembl = useMart("ensembl",dataset="hsapiens_gene_ensembl")
getBM(attributes='hgnc_symbol', 
      filters = 'ensembl_gene_id', 
      values = ensemblsIDS, 
      mart = ensembl)