Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading and Writing CSV Files in R: Introduce na.strings argument and explain how to read CSV file by providing a filename only #387

Closed
mrakovic opened this issue Jul 30, 2018 · 4 comments

Comments

@mrakovic
Copy link

@mrakovic mrakovic commented Jul 30, 2018

Hi everyone,
I would like to offer two suggestions related to the lesson "Reading and Writing CSV Files in R":

  1. In most cases, researchers need to deal with missing data in their datasets, so introducing na.strings argument (among other read.csv arguments introduced in the lesson so far) may be a useful complement for those researchers who want to know, for example, how to convert empty cells in a dataframe to a NA string - conventional label that R understands as missing data point.
  2. From my experience, some researchers prefer to place their CSV files into a working directory (root level, without using subfolders), so having this scenario covered in the read.csv introduction may be an addition worth considering. For example, read.csv(file = 'car-speeds.csv') will locate and read the file if it exists in a working directory (assuming that working directory was properly set before).
    Looking forward to reading your comments.
    Mladen
@diyadas
Copy link
Contributor

@diyadas diyadas commented Jul 31, 2018

Hi Mladen! Thanks for your comments.

  1. I could see a case for this, especially as na is covered as an argument in write.csv later on, but I'd like @katrinleinweber to weigh in on this as well before proceeding.

  2. I would actually caution against this. I believe it's more helpful to have learners understand how to get data that is not stored in the same location as their working directory and I find it good practice to separate scripts vs. data. I also feel like a lot of the particulars of navigating directories are covered well in the Unix shell lesson (which is often taught just prior to the R lesson in many Carpentry workshops).

Loading

@katrinleinweber
Copy link
Contributor

@katrinleinweber katrinleinweber commented Jul 31, 2018

Hello :-) I agree with @diyadas' 2. argument.

About 1.: The argument is also intended for cases in which the raw data contains something else, like n.a., --, etc. It can also take a c()ombination of several strings. I think a PR changing exactly the phrases that you mean, or adding what you want to see included, would be best to decide. If you do, please include a "(fix #387)" in your commit message. It will unlock a little GitHub magic ;-)

Loading

@EastBayEv
Copy link

@EastBayEv EastBayEv commented Feb 12, 2020

This is a great point! While the "Import Dataset" button is handy, I cannot find a way to pass a vector of na.strings into that field when using the "Import Dataset" button (only single values), thus making the hard-coding of read.csv even more valuable.

Does anybody know if you can indeed pass a vector of na.strings into that field whilst using the "Import Dataset" button?

Loading

@PaulMelloy
Copy link
Contributor

@PaulMelloy PaulMelloy commented Dec 1, 2020

Hello, I have added a pull request to try and address this issue. #494
I thought the addition would be best suited in the "Reading and Writing CSV Files" episode. I attempted to make it a challenge question after the stringsAsFactors argument topic.
Let me know if you think there are better data sets than the two I used as an example and I could edit it.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants