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

Adding options(stringsAsFactors=FALSE) #419

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
3 participants
@katrinleinweber
Copy link
Collaborator

commented Apr 21, 2019

Revisiting #393, I noticed that @duytpm16's commit was not in any PR, yet. It:

add['s] a little section on options(stringsAsFactors = FALSE) under The stringsAsFactors Argument[and] add['s] a short line of code as well to show how it works. […]

I am a bit skeptical of options() (similarly to setwd() or rm(list = ls())) to be honest, but it at least works only during the current session.

The alternative would be to solve @duytpm16's usecase

don't … manually set stringAsFactors to FALSE when … reading in multiple files

by teaching to wrap the read… function into a custom one, similarly to the "Functions to Create Graphs" challenge. See esp. my last review comment, but I wanted to give this suggestion a fair chance & discussion.

Adding options(stringsAsFactors=FALSE)
Hello,

I have made some changes based on Diya's suggestion in #393 to add a little section on options(stringsAsFactors = FALSE) under  `The `stringsAsFactors` Argument`.  I  added a short line of code as well to show how it works. Please have a look at the changes and let me know if additional changes are needed.


Thanks, 
Duy

@katrinleinweber katrinleinweber requested a review from diyadas Apr 21, 2019

@katrinleinweber
Copy link
Collaborator Author

left a comment

@duytpm16: Please have a look at the review comments.

@@ -115,6 +115,19 @@ carSpeeds$Color
```

That's better! And we can see how the data now is read as character instead of factor.



This comment has been minimized.

Copy link
@katrinleinweber

katrinleinweber Apr 21, 2019

Author Collaborator

Do we need this many newlines above & below? I think 1 or 2 are enough separators.

Alternatively, if we want to prevent characters from converting to factors, we can change R's default behavior by using `options(stringsAsFactors=FALSE)`. This will change the default value of the 'stringsAsFactors' argument to FALSE in all functions that utilize this parameter without us having to do so manually.

```{r optionsStringsAsFactorFALSE}
options(stringsAsFactors=FALSE)

This comment has been minimized.

Copy link
@katrinleinweber

katrinleinweber Apr 21, 2019

Author Collaborator

Does RStudio's Code > Reformat… leave the = without surrounding spaces? If not, please update L121 as well.

This comment has been minimized.

Copy link
@diyadas

diyadas Apr 29, 2019

Collaborator

(Reformat code adds spaces, so please update.)

str(carSpeeds)
```

See ?options for more details about the function and a list of other default settings that can be changed.

This comment has been minimized.

Copy link
@katrinleinweber

katrinleinweber Apr 21, 2019

Author Collaborator

Would this be a good place to mention that each options() change is valid only during the current R session?

Since this touches on using .Rprofile to change the defaults permanently and on rather teaching the saner tidyverse defaults (see #276), I'm worried that this change risks bloating the lesson. Hence my "alternative" suggestion in the PR's description.

This comment has been minimized.

Copy link
@diyadas

diyadas Apr 29, 2019

Collaborator

Agreed. I might even suggest a change above, to line 121, and abandon this part:

If we want to prevent characters from converting to factors, we can change R's behavior in the current session by using options(stringsAsFactors = FALSE). See ?options for more details about the function. Note that any changes made using options will not be reflected in a new R session, unless the command is re-run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.