read in buried file

I figured it out... -> session -> set working directory -> files pane location
make sure you are in the active folder in the folder's tab

caveat: see nwerth's comment below

original problem:

here's my code:

trees <-read.nexus("AMD_phylogeny_tree_files_1000.nex")

the file is buried in "Home > Cfiles > AMD_morphology" (i can see the file in the files pane to the right)

how do i change the "read" command to get to that file?

here's the error message i get:

Error in file(file, "r") : cannot open the connection
In addition: Warning message:
In file(file, "r") :
cannot open file 'AMD_phylogeny_tree_files_1000.nex': No such file or directory

Thanks

Hi @c_e_c

In my experience, this error only occurs if either the working directory is not set to the correct location or the name of the file within the double quotes is not the same as the actual file name.

For the former type getwd() in the console to verify if the correct location is set as the working directory. For the later press F2 after selecting the file, copy the name and paste it within the double quotes.

Let me know if this works.

Warm Regards,
Pritish

Changing the working directory as part of a workflow is usually a bad idea. It can mess with other things, and there's usually a better way to do it.

For your example, you can run this command instead:

trees <- read.nexus("~/Cfiles/AMD_morphology/AMD_phylogeny_tree_files_1000.nex")

Note that the tilde (~) at the beginning of the file name tells R the base of the path is the Home directory.

If you're not familiar with using file paths in code, check out the Wikipedia page on Path (computing).