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

An addition to the solution for Exercise 14.2.1 #612

Open
AnttiRask opened this issue Apr 30, 2022 · 1 comment
Open

An addition to the solution for Exercise 14.2.1 #612

AnttiRask opened this issue Apr 30, 2022 · 1 comment

Comments

@AnttiRask
Copy link

This is all well and good:

"Since str_c() does not separate strings with spaces by default it is closer in behavior to paste0()."

str_c("foo", "bar")
#> [1] "foobar"

But after that I would add something like this:

"However, with the use of the "sep" argument, str_c can replace both paste and paste0.

str_c("foo", "bar", sep = " ")
#> [1] "foo bar"

Link to the page: https://jrnold.github.io/r4ds-exercise-solutions/strings.html#exercise-14.2.1

Thank you!

@AnttiRask
Copy link
Author

Also, if you really want, you can get the same results for these ones by using str_replace_na(NA).

str_c("foo", str_replace_na(NA), sep = " ")
#> [1] "foo NA"

instead of

paste("foo", NA)
#> [1] "foo NA"

and

str_c("foo", str_replace_na(NA))
#> [1] "fooNA"

instead of

paste0("foo", NA)
#> [1] "fooNA"

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

No branches or pull requests

1 participant