Watts-College / cpp-528-fall-2021

https://watts-college.github.io/cpp-528-fall-2021/
2 stars 2 forks source link

Lab 02 - Error in file: cannot open the connection #10

Open aawoods97 opened 3 years ago

aawoods97 commented 3 years ago

Good evening Professor,

I am attempting to import the data dictionary in my lab rmd file. I am receiving the following error: "Error in file(file, "rt") : cannot open the connection". How can I ensure my rmd file is able to locate the data dictionary?

Thank you for your assistance! Asia Woods

castower commented 3 years ago

Hello Asia @aawoods97,

Are you working within an RStudio project?

Also, can you provide the following:

  1. The file path to your data dictionary
  2. The code you are running for the import
  3. The results of running here() [without any code in the parentheses] in one of your code chunks.

Thanks! Courtney

aawoods97 commented 3 years ago
  1. The path for my data dictionary: "/Users/asiawoods/Documents/GitHub/CPP527/rodeo/ltdb-data-dictionary.csv" I watched the video that mentioned this should not be a path that directly correlates with my computer, but one that connects to GitHub. However, I am not sure how to do that.

  2. Code for the input: `DD_FILEPATH <- here::here( "data/rodeo/ltdb_data_dictionary.csv" )

import data dictionary

dd <- read.csv( DD_FILEPATH, stringsAsFactors=F )`

  1. Results of here() and error for importing data dictionary
Screen Shot 2021-10-25 at 7 49 25 PM
castower commented 3 years ago

Hello Asia,

Thanks!

The best way to think about the here package is that it splits your code path into two.

So here has stored: /Users/yourusername/Documents/GitHub/CPP527

You will need to enter the second half of the path to complete the code. I believe your error is coming from the '/data/' file as it appears your file is stored directly in rodeo.

Try the following code to complete your code path:

DD_FILEPATH <- here::here( "rodeo/ltdb_data_dictionary.csv" )

To connect your RStudio to Github, you can download Git here: https://git-scm.com/downloads and then this video shows how to set up a Github project from your team's repository: https://www.youtube.com/watch?v=A5W8mQf8ej8&t=2s

Let me know if you have any further questions! Courtney

aawoods97 commented 3 years ago

I tried the file path, but it still did not work. I also attempted to create a GifHub project as instructed in the video. However, I am receiving the following error:

/usr/bin/git clone --progress https://github.com/R-Class/cpp-528-fall-2021-group-03 cpp-528-fall-2021-group-03 Cloning into 'cpp-528-fall-2021-group-03'... remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. fatal: Authentication failed for 'https://github.com/R-Class/cpp-528-fall-2021-group-03/'

I have signed up for two-factor authorization and used one of the tokens as the password, but I am still not able to create a project. How can I go about fixing this error to create a project?

castower commented 3 years ago

Hello @aawoods97

You can try the steps here to set your access token: https://gist.github.com/Z3tt/3dab3535007acf108391649766409421

If that still does not work, you can install GitHub Desktop and pull the repository from there by selecting existing directory: https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects?mobile_site=true

Does the here package code work if you enter the entire file path?

aawoods97 commented 3 years ago

I believe I have already pulled the repository using GitHub Desktop, as pictured below. I am able to push and pull things to and from the GitHub page.

Screen Shot 2021-10-26 at 7 00 52 AM

If I use the code below, the data dictionary uploads to the global environment properly and I am able to run my functions using that data.

dd <- read.csv("/Users/asiawoods/Documents/GitHub/CPP527/cpp-528-fall-2021-group-03/data/rodeo/ltdb-data-dictionary.csv")

castower commented 3 years ago

Hello Asia,

Great! I'm glad Github Desktop is working. If you hover over 'Current Repository cpp-528-fall-2021-group-03' it will show you the location of the repository on your computer. You can then add it to RStudio by clicking Project > New Project > Existing directory and then selecting the location of the repository:

rproject-from-existing-directory

Also, your original listed file location was missing the cpp-528-fall-2021-group-03 folder.

If here() still results in /Users/yourusername/Documents/GitHub/CPP527,

Your code should be:

DD_FILEPATH <- here::here( "cpp-528-fall-2021-group-03/data/rodeo/ltdb_data_dictionary.csv" )
dd <- read.csv( DD_FILEPATH, stringsAsFactors=F)
aawoods97 commented 3 years ago

I think I might have missed something because I am still getting the same output. I added a project, but it appeared within the cpp-528-fall-2021-group-03 folder.

Screen Shot 2021-10-26 at 11 36 30 AM

I am also receiving the error when attempting to read the csv `# store data dictionary file path DD_FILEPATH <- here::here( "cpp-528-fall-2021-group-03/data/rodeo/ltdb_data_dictionary.csv" )

import data dictionary

dd <- read.csv( DD_FILEPATH, stringsAsFactors=F)

remove the second root column

dd <- select( dd, -root2 )

view a subset of columns

dd[ c(1:5,15:17), ] %>% pander()`

Also when I call the here() function I am given the following: here() starts at /Users/asiawoods/Documents/GitHub/CPP527

castower commented 3 years ago

Hello Asia, Do you have the project open in RStudio?

aawoods97 commented 3 years ago

I have opened the project in another window in RStudio. When the window opens it there are no files opened, but I do see something in the lower right hand corner with either the path to the project or something similar, I don't have access to my computer or else I would include a picture.

I have opened both files in the new window for the project.

I am not sure if this is helpful, but when I edit the files, I receive updates on the GitHub Desktop with the option to push it to GitHub.

castower commented 3 years ago

When you run here() in the new window are you given the same file path as before?

aawoods97 commented 3 years ago

When I run here() I get the following: "/Users/asiawoods/Documents/GitHub/CPP527"

I have attached an image of the lower right-hand corner I mentioned earlier.

Screen Shot 2021-10-26 at 9 38 38 PM
castower commented 3 years ago

@aawoods97 Do you see the project listed in the top right corner of Rstudio?

castower commented 3 years ago

You should see something similar to the highlight in the top right here:

rproject-from-existing-directory

castower commented 3 years ago

Here is a screenshot of a project loaded in the top right corner: rproject

aawoods97 commented 3 years ago

This is what I see in the top right corner.

Screen Shot 2021-10-26 at 10 16 14 PM

The name of my project is "cpp-528-template.Rproj" and is included in the cpp-520...group-03 folder

castower commented 3 years ago

Okay, perfect. Your project is loaded. Have you installed the renv package?

If so, try:

detach("package:here", unload=TRUE)
library(here)
here()
aawoods97 commented 3 years ago

This was my result:

Screen Shot 2021-10-26 at 10 37 43 PM
aawoods97 commented 3 years ago

The file name of the data dictionary uses dashes instead of hyphens... I fixed the file name and it works........ Thank you for your time!!

castower commented 3 years ago

Ah, good catch @aawoods97! Glad it's working.