I have a file with list of paths to URLs and and files that resembles the extract bellow:
url_some_dta <- "url_goes_here" backup_some_dta <- "path to the backup rds file goes here" url_exotic_dta <- "another_url" backup_exotic_dta <- "some backup rds file" url_mysterious_dta <- "url goes here" backup_mysterious_dta <- "backup rds file for myst. dta"
I'm reading those files via the
source(file = "urls_queries_files.R", local = TRUE)
When I list the objects, the objects appear in the alphabetical order:
> ls()  "backup_exotic_dta" "backup_mysterious_dta" "backup_some_dta" "url_exotic_dta"  "url_mysterious_dta" "url_some_dta"
This is problematic, as I'm interested in reading those objects in the order they are listed in the original file (urls_queries_files.R). The reason being that I want to draft a short script that will create backup
rds files upon the successful download of the URL. I will draft a simple loop that performs the download using the value from the first object and if this is successful saving the
rds file (the
rds files and
URLs are later used to populate data frames). All of that is fairly straightforward, but it would be much simpler if I could refer to the objects in the way they are listed in the original file. I could simply then:
all_objs <- ls()
and make my operations by:
all_objs[i+1]. It appears that
ls with sorting set to
FALSE also does not return the desired results:
> ls(sorted = FALSE)  "url_mysterious_dta" "url_exotic_dta"  "backup_mysterious_dta" "backup_exotic_dta"  "url_some_dta" "backup_some_dta"
My questions are:
- How to list R objects in the order they are typed in the source file?
- Out of curiosity: Running
sorted = FALSEappears to return a list that does not correspond to what was typed in the source file. Consequently, I'm wondering how does
sourcecommand determine which object appears first on the list ?