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

Consider raising attention to the potential ambiguity of the assignment arrow (<-) operator. #406

Open
massaraevi opened this issue Jul 30, 2022 · 6 comments
Labels
good first issue Good issue for first-time contributors help wanted Looking for Contributors

Comments

@massaraevi
Copy link

In the section "Intro to R" of the Instructor Notes, the assignment arrow operator (<-) is discussed. This is a good point to warn readers of the potential ambiguity of the operator in R. Since the operator consists of a symbol that resembles the "less than" comparison operator (<) and the minus symbol (-) for subtraction, if we have a logical expression like x<-5 (is x less than -5), the R interpretor may interpret this instruction as an assignment of 5 to x. In this case, the solution (and the general good coding practices recommendation) is to use spaces to reduce ambiguity. Therefore, if the intention is for a logical expression, it should be written as "x < -5" or if the assignment is intended, it should be "x <- 5".

@juanfung
Copy link
Contributor

juanfung commented Aug 1, 2022

hi @massaraevi thank you for the observation! i think an additional bullet explaining this would be a nice addition to the instructor notes. would you be interested in submitting a PR?

@juanfung juanfung added status:waiting for response Waiting for Contributor to respond to maintainers' comments or update PR good first issue Good issue for first-time contributors labels Aug 1, 2022
calyssaherrera added a commit to calyssaherrera/r-socialsci that referenced this issue Sep 2, 2022
@fengxia9
Copy link

I think this is a good catch. Anytime, the <- together would be the assignment arrow operator.

@mbplatt
Copy link

mbplatt commented Dec 15, 2022

The spacing would certainly work, however, I think novices often have difficulty differentiating between when spaces matter and when they do not. This could be potentially confusing. An alternative would be to place the negative number in parentheses "x < (-5)". That would make it easier to differentiate between the two.

@Dr-Ivis-Renee-King
Copy link

Hi @mbplatt, this suggestion seems like a good example for novice learners to practice using the assignment operator. I believe it would be a good alternative to include it as a Note for the instructor along with a tip to use the shortcut feature for the assignment operator. So the learner will distinguish wanting to use the operator instead of assigning x to -5.

@jdrasmus1
Copy link
Contributor

Looking at the lesson, I thought of few ways this could be clarified, depending on how generally it to be addressed:

  1. Simple parenthetical for example on line 60: "in syntax, it is good practice to always use <- for assignments (note the spaces before and after the arrow)."
  2. More general clarification in the paragraph below about style for objects, e.g. on line 71: "You want your object names to be explicit and not too long. Generally, objects are separated from other objects and operators (like the the <- arrow) with spaces so cannot include spaces."
  3. An even more note for the instructor that normalizes typos with quotations, parentheses, capitalization, and spaces.

@juanfung
Copy link
Contributor

@jdrasmus1 that all sounds good to me. would you be interested in submitting a PR with those changes?

@juanfung juanfung added help wanted Looking for Contributors and removed status:waiting for response Waiting for Contributor to respond to maintainers' comments or update PR labels Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good issue for first-time contributors help wanted Looking for Contributors
Projects
None yet
Development

No branches or pull requests

6 participants