0

I'm opening ebird data with auk, having trouble creating a path for the file. I set the path to a folder. When I try to change it to a file it says the path is not true.

with the Sys.getenv() I can see the path is set to a folder. with the auk_get_ebd_path() command I see the same thing. When I try to change the path to a file inside that folder with the auk_set_ebd_path() command I receive an error message.

library(auk)
auk_get_ebd_path()
[1] "/Users/lucypullen/Documents/bird/data"
auk_set_ebd_path("/Users/lucypullen/Documents/bird/data/ebd_CA_relApr-2019.txt", overwrite = TRUE)
[1] Error: dir.exists(paths = path) is not TRUE

other attempts yeilded an Error in file(con, "r") : cannot open the connection message

Warning messages: 1: In file(con, "r") :
  'raw = FALSE' but '/Users.....data/CA' is not a regular file
2: In file(con, "r") :
  cannot open file '/Users/lucypullen/Documents/bird/data/CA': it is a directory

seems like they want the path to go to a file. I thought the path would be complete with the system.file() command. I've tried a bunch of variations:

input_file <- system.file("/Users/lucypullen/Documents/bird/data/CA/ebd_CA_relApr-2019.txt", package = "auk")

or

input_file <- system.file("ebd_CA_relApr-2019.txt", package = "auk")

or

input_file <- system.file("~/ebd_CA_relApr-2019.txt", package = "auk")
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • Why are you giving the auk_set_ebd_path function the name of a file? That makes no sense. "Paths" are names of directories, not of files. – IRTFM Jun 06 '19 at 22:13
  • because R returns an error message that seems to suggest it is looking for a file: Warning messages: 1: In file(con, "r") : 'raw = FALSE' but '/Users.....data/CA' is not a regular file 2: In file(con, "r") : cannot open file '/Users/lucypullen/Documents/bird/data/CA': it is a directory – Lucy Pullen Jun 10 '19 at 18:19
  • This: "/Users/lucypullen/Documents/bird/data/ebd_CA_relApr-2019.txt" is the name of a file, not the name of a directory. The error says the directory does not exist. The rest of what you are referring to is not an error message, it's a warning. Not the same thing. I installed that package and ran you code and I get `NA` from: `auk_get_ebd_path()`, so you must have done something to set up your path. – IRTFM Jun 10 '19 at 21:01
  • You also didn't say what happened with you calls to `system.file`. That is a method of getting at the sample ebd file that comes with the auk package, so you would expect it to be actually located in one of your library directories, none of which you appear to be addressing. You should execute: `f_in <- system.file("extdata/ebd-sample.txt", package = "auk")` and see what you get. I get a full path and file name when I do that. The path is the first item that is returned by `.libPaths()` and don't forget the period. – IRTFM Jun 10 '19 at 21:14
  • the sample works for me too, but, problems occur when working with the actual dataset – Lucy Pullen Jun 11 '19 at 00:15

1 Answers1

0

I suspect you should be doing this, since there appears to have been some sort of setup operation that preceded this question:

my_ebd_path = auk_get_ebd_path()  # since you appear to already set it.
my_full_file_loc <- paste0(my_ebd_path, ”/“, "ebd_CA_relApr-2019.txt")
my_ebd_data <- read_ebd(my_full_file_loc)

str(my_ebd_data)
# ------what I get with the sample file in the package--------------
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   494 obs. of  45 variables:
 $ checklist_id                : chr  "S6852862" "S14432467" "S39033556" "S38303088" ...
 $ global_unique_identifier    : chr  "URN:CornellLabOfOrnithology:EBIRD:OBS97935965" "URN:CornellLabOfOrnithology:EBIRD:OBS201605886" "URN:CornellLabOfOrnithology:EBIRD:OBS530638734" "URN:CornellLabOfOrnithology:EBIRD:OBS520887169" ...
 $ last_edited_date            : chr  "2016-02-22 14:59:49" "2013-06-16 17:34:19" "2017-09-06 13:13:34" "2017-07-24 15:17:16" ...
 $ taxonomic_order             : num  20145 20145 20145 20145 20145 ...
 $ category                    : chr  "species" "species" "species" "species" ...
 $ common_name                 : chr  "Green Jay" "Green Jay" "Green Jay" "Green Jay" ...
 $ scientific_name             : chr  "Cyanocorax yncas" "Cyanocorax yncas" "Cyanocorax yncas" "Cyanocorax yncas" ...
 $ observation_count           : chr  "4" "2" "1" "1" ...
 $ breeding_bird_atlas_code    : chr  NA NA NA NA ...
 #----snipped a bunch of output---------
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Hello and thanks for the example. I tried it. R says the file does not exist. – Lucy Pullen Jun 10 '19 at 21:49
  • ok. thanks for the tips about how to navigate the r directory. when I run the `.libPaths()` function the path is `"C:/Users/Owner/OneDrive/Documents/R/win-library/3.6"` – Lucy Pullen Jun 10 '19 at 21:57
  • when I run your example `my_full_file_loc <- paste0(my_ebd_path, "ebd_CA_relApr-2019.txt")` and call `my_ebd_data <- read_ebd(my_full_file_loc)` there is no slash between the folder and the file. The message is `Error: Path C:/Users/Owner/OneDrive/Documents/Bird_Projectebd_CA_relApr-2019.txt' does not exist ` – Lucy Pullen Jun 10 '19 at 22:40
  • 1
    adding a forwardslash here `my_full_file_loc <- paste0(my_ebd_path, "/ebd_CA_relApr-2019.txt")' seems to do the trick – Lucy Pullen Jun 11 '19 at 01:05
  • Right. There’s a better function and I’ll look it up. – IRTFM Jun 11 '19 at 04:23