Conversion str to variable

Hello !

I have a code like this :

   path = "Path"
   file = "File"
   read_excel(paste0(path,file)) -> PathFile

I tried

    read_excel(paste0(path,file)) -> type.convert(paste0(path,file), dec=".")

but it doesn't work. I want to put the Excel in a variable named PathFile but using the string "Path" and "File". How to do it ?

Thanks !

You can have a look at ?assign()

Nice thank you. I have a similar problem. I want to use the function full_join but I can't use a str. I tried :

paste0(path,file) %>% full_joint(paste0(path2,file2), by=c("column1"))

To do something like

PathFile %>% full_join(Path2File2, by = c("column1"))

where PathFile and Path2File2 are data come from read_excel.

Thank you again

this is a typo

you can use get() to get the dataframe associated with a name (which you can make by pasting together parts of names). its the inverse of assign().

(ex1 <- data.frame(
  joinbyme =c(1,2,3),
  letters = letters[1:3]
))

(ex2 <- data.frame(
  joinbyme =c(1,2,3),
  LETTERS = LETTERS[1:3]
))

full_join(get(paste0("ex",1)),
          get(paste0("ex",2)),
          by="joinbyme"
)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.