You can use biomaRt
GENES = useMart("ENSEMBL_MART_ENSEMBL", dataset = "hsapiens_gene_ensembl", host = "useast.ensembl.org")
YouRange<- getBM(attributes = c("chromosome_name", "start_position", "end_position"), filters = c("chromosome_name","start","end"), values = list(chromosome_name = "4", start = 50000-3000, end = 50000 + 3000), mart = GENES)
You can use getSequence
get sequences.
getSequence(chromosome = 4, start = 50000-3000, end = 50000+3000,type='hgnc_symbol',seqType = 'gene_exon_intron', mart = GENES)
getBM
helps you get the annotation information from Biomart, getSequence
helps you get the sequence you need.
This is a simple example for example question, you can check details of biomaRt to solve your specific question.
Do you have to do this with R specifically?
Yes (unfortunately).