0

I am afraid my question is pretty basic :

I create a dataframe that I name using a paste command as I want to have the date each time.

assign(paste(Fichier, Onglet2, Budget,Tour, Date,sep="_"),
       FichierExcel %>%
         read.xlsx(., sheet="DM", colNames=F, rows=(2:209)) %>%
         set_names(Colonnes_DemandeMondiale))

So I get a dataframe that is named paste(Fichier, Onglet2, Budget,Tour, Date,sep="_"), but when I try to check it by using the headtail function, it does only seem to see it as the string that results from the paste, not the datagframe itself.

> headtail((paste(Fichier, Onglet1, Budget,Tour, Date,sep="_")))
Erreur : 'x' must be a matrix or data.frame.

How should I specify that I want the object which name is the charater chain and not the character chain itself ?

Anthony Martin
  • 767
  • 1
  • 9
  • 28
  • Use `get` : `get(paste(Fichier, Onglet1, Budget,Tour, Date,sep="_"))` – Ronak Shah Aug 26 '20 at 08:25
  • @RonakShah Please no. This is almost never the correct solution when this question gets asked on here. I’m sure you know that. – Konrad Rudolph Aug 26 '20 at 08:27
  • @KonradRudolph Hmm I am then curious as to why this is not the correct solution, if you may elaborate (or redirect me to another post of course) – Anthony Martin Aug 26 '20 at 08:56
  • @AnthonyMartin Because for virtually all practical purposes, variable names should be treated as static, prescribed solely by the code you write; this makes the behaviour of the code exponentially easier to reason about and check. If you need dynamic names, use named vectors/lists. In fact, what your code should be doing is read XLSX sheets into *one* list of tables (or possibly into one large table), not into separate variables. – Konrad Rudolph Aug 26 '20 at 09:46

0 Answers0