Here supply this BioSeqUtils R package to extract different features (UTR, exon, CDS, intron, gene) sequence of gene/transcript from your local genome and annotation files in R. Besides there are many other tools for you to achive this. Also supplying other useful functions to do some interesting things. Any question or advice can be pushed on github Issues panel.
You can install the development version of BioSeqUtils like so:
# install.packages("devtools")
devtools::install_github("junjunlab/BioSeqUtils")
library(BioSeqUtils)
Jun Zhang (2023). BioSeqUtils: Extract Sequence from Genome According to Annotation File. https://github.com/junjunlab/BioSeqUtils