I have read several topics in which users would advise against the use of the get()
and assign()
functions as it alters readibility of the code, which I cannot deny (for instance here).
But then I am a bit lost as to be good practice.
I have an example currently : I have a pdf with tables about several countries, which I import as a dataframe CF_Brut_pdftools
.
My list of countries is ListePays=c("US","JP","DE","FR","UK","IT","CA","ZE","NL","NO","ES","SE","CH")
I have already a list of pages to use for each country. So I do
for (Pays in ListePays){
assign(paste("CF",Pays,sep="_"),CF_Brut_pdftools[get(paste("Page",Pays,sep="_"))])
}
And the I have some data manipulation, for isntance :
for (Pays in ListePays2){
assign(paste("CF",CF,"2",sep="_"),as.list(strsplit(get(paste("CF",Pays,sep="_")), "\n") [[1]]))
}
That will continue for several steps
What would be better options than this way ?
It is not straightforward to have a MWE in this case, but I can work on one if it helps.