Beginner: Choosing where to write xls files to

Please forgive if the code looks bad or if this is a dumb question, I'm brand new to R. Can someone help me on how to choose where I am saving the excel file to locally. That's what I'm attempting to do with the "c:\Users\Tommy Mulflur\Desktop\decstats.xlsx" but that is for some reason being included in the entire name of the document and where it gets saved is a nightmare. Can only go find it about 50% of the time

writexl::write_xlsx(decstats, "c:\\Users\\Tommy Mulflur\\Desktop\\decstats.xlsx")

different systems have different conventions around path delimiters, its generally advisable to have R construct a path for you by using file.path()
perhaps

writexl::write_xlsx(decstats,
                    file.path("C:","Users","Tommy Mulflur","Desktop","decstats.xlsx"))

also if theres any doubt about the directory , you can check if R undserstands it exists with something like

dir.exists(file.path("c:","Users"))
dir.exists(file.path("c:","Users","Tommy Mulflur"))

maybe adding it up iteratively will show you if you have a typo or somesuch along the way

Ok got it thank you so much! I tried parsing it up step by step and it returns false on either of the two below. I am now looking into creating/setting a directory. Always another challenge to go tackle!

dir.exists(file.path("c:"))
[1] FALSE

dir.exists(file.path("c:", "Users"))
[1] FALSE

Any suggestions on this one?

Does seem strange. If you ask r to give you a temporary directory, what path does it return?

tempdir()

Also, what is your working directory?

getwd()

?

Thank you for getting back!

My working directory is

getwd()
[1] "/Users/tommymulflur"

And the temporary director generates

tempdir()
[1] "/var/folders/bc/6d6w7cp955bgscm_ktl7hhyc0000gn/T//Rtmp86ArcY"

I am trying to push down the working directory route. Think I'm making progress

I figured it out! Thank you so much. I can send the correct code if your curious.

I'm sure I'll have more silly questions soon. So much fun, but so much to learn!

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.