I have some code in Rstudio which sends an API request to Google Big Query to run a saved query. Then my script downloads the data back to RStudio to be modelled to a machine learning model. 

Its a lot of medical data and I would like some of the process to be even more automated than before.

```
tags<-read.csv('patient_health_codes.csv',stringsAsFactors = FALSE)
tags<-tail(tags, 6)

```

this section takes a CSV to iterate over patient health groups (such as Eczema is 123456) - Section 1

```
MD2DS="2018-07-20" 
MD2DE="2018-07-20" 

```

This section above fills in date periods for the query execution function - Section 2

```
sapply(health_tags$ID, function(x) query_details (MD2_date_start=MD2SE,    
                                                  MD2_date_end=MD2DE,                                                      
                                                Sterile_tag=as.character(x)))

```

This section executes the query on google big query and iterates over all the different patient groups in x i.e Eczema, Asthma, Allergy Group, and so on. -Section 3

```
project <- "private-health-clinic"
bq_table=paste0('[private-health-clinic:medical.london_',Sterile_tag,']')
sql =paste0('SELECT * FROM ', bq_table)

```

This section names each table after its patient group - section 4

```
data <- query_exec(sql, project = project, max_pages = Inf)
write.csv(data, file =paste0("medical_", Sterile_tag, ".csv"))

```

This code downloads and writes the big query table as a CSV on RStudio - Section 5

My question is, how do I tell RStudio when someone executes section 3 after 1 hour in real time please execute section 4 then 5 mins after execute section 5.

In advance thank you for the help I'm not an R expert!