In R you can use the fantastic TCGAbiolinks package. You can find a thorough explanation here at the Bioconductor webpage. I have used the following script to do just what you want to do:
library("TCGAbiolinks")
library("SummarizedExperiment")
DIRPREFIX <- "/PATH/"
## Download raw counts for indicated sets
## Example of TCGA.data.sets: c("TCGA-LUAD", "TCGA-SKCM")
for (id in TCGA.data.sets){
query <- GDCquery(project = id,
## get data.category using for instance TCGAbiolinks:::getProjectSummary("TCGA-LUAD")
data.category = "Transcriptome Profiling",
## see link above for data.types and workflow.types
data.type="Gene Expression Quantification",
workflow.type = "HTSeq - Counts")
GDCdownload(query, method = "client", directory = "~/Downloads/")
data <- GDCprepare(query, directory = "~/Downloads/")
save(data, file = file.path(DIRPREFIX, paste0(id, ".Rdata")), compress = "xz")
}