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

remove most usages of <- #3592

Merged
merged 7 commits into from
May 24, 2019
Merged

remove most usages of <- #3592

merged 7 commits into from
May 24, 2019

Conversation

MichaelChirico
Copy link
Member

@MichaelChirico MichaelChirico commented May 24, 2019

Closes #3590

On the way home I thought of a simple regex to accomplish this, after a few tweaks it's still pretty simple (this is for mac sed so the command may need adjustment on other platforms):

for f in R/*; do sed -i '' -E 's/^([^(]+[^<[)])<-([^."`]|$)/\1=\2/g' $f; done

[^(]+ ensures it's not defined within-line as a function argument; [^<[) ensure it's not [<-, <<-, or ()<-. [^."`] covers cases like "key<-" and dimnames<-.data.table.

There's one false positive (fread.R):

      warning = fun <- function(e) {

^ this is defining fun for the warning for tryCatch which is then recycled to error

After this grep -r "<-" R | wc -l is down to 145 from 628.

There are some false negatives:

R/fcast.R:    if (!length(nm)) nm <- paste0("fun", i)
R/IDateTime.R:  if (tz == "") tz <- "UTC"
R/data.table.R:  names(i) <- NULL

Some of these can be hit with a regex targeting the part of the line after <-:

for f in R/*; do sed -i '' -E 's/ <-([^()]*[^,])$/ =\1/g' $f; done

After this we're down to grep -r "<-" R | wc -l = 135

Still a small number of false negatives, fine to ignore. 135 is still tediously large to do by hand & most are true positives.

R/setkey.R:        if (ix != 0L) ans <- point(ans, i, x, ix) # see 'point' in data.table.R and C-version pointWrapper in assign.c - avoid copies

@codecov
Copy link

codecov bot commented May 24, 2019

Codecov Report

Merging #3592 into master will increase coverage by 0.06%.
The diff coverage is 98.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3592      +/-   ##
==========================================
+ Coverage   97.63%   97.69%   +0.06%     
==========================================
  Files          66       66              
  Lines       12721    12721              
==========================================
+ Hits        12420    12428       +8     
+ Misses        301      293       -8
Impacted Files Coverage Δ
R/shift.R 96.29% <ø> (ø) ⬆️
R/xts.R 100% <ø> (ø) ⬆️
R/transpose.R 96.29% <ø> (ø) ⬆️
R/cedta.R 87.5% <ø> (ø) ⬆️
R/tables.R 96.87% <ø> (ø) ⬆️
R/setops.R 99.48% <ø> (+0.51%) ⬆️
R/openmp-utils.R 100% <ø> (ø) ⬆️
R/like.R 100% <ø> (ø) ⬆️
R/timetaken.R 100% <ø> (ø) ⬆️
R/getdots.R 100% <ø> (ø) ⬆️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df28194...4358304. Read the comment docs.

@mattdowle mattdowle added this to the 1.12.4 milestone May 24, 2019
R/data.table.R Outdated
@@ -1151,7 +1151,7 @@ replace_dot_alias <- function(e) {
# Note that the NAMED(dt)>1 doesn't work because .Call
# always sets to 2 (see R-ints), it seems. Work around
# may be possible but not yet working. When the NAMED test works, we can drop allocwarn argument too
# because that's just passed in as FALSE from [<- where we know `*tmp*` isn't really NAMED=2.
# because that's just passed in as FALSE from [= where we know `*tmp*` isn't really NAMED=2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see three places where you've changed [<- to [=, and two with $&lt;- to $= (all in comments). I guess there could be other thing<- cases but didn't notice them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good eye, thanks. shouldn't be any in actual code (tests compile & run)

the key is if you use it in actual code, it's gotta be backticked or quoted (`[<-` or "[<-"), which is caught by the regex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway the regex could be fixed, previous character should be not-[<[]

@@ -90,9 +90,11 @@ round.IDate <- function (x, digits=c("weeks", "months", "quarters", "years"), ..
(setattr(as.integer(unclass(e1) + unclass(e2)), "class", c("IDate", "Date"))) # () wrap to return visibly
}

`-.IDate` <- function (e1, e2) {
if (!inherits(e1, "IDate"))
`-.IDate` = function (e1, e2) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part of the overall diff is not just <- removal... made this slight change in the second commit (coverage).

I was a bit wary of dispatching to -.Date since the result could then be Date. But the if ( isReallyReal(e2) ) branch below does the same.

@mattdowle
Copy link
Member

I was just fixing those new tests too as I thought you'd be asleep :-)

## passing Date to second argument of as.POSIXct.ITime
t = as.ITime(0L)
test(2051.5, as.POSIXct(t, .Date(0L)), .POSIXct(0, 'UTC'))

Copy link
Member

@mattdowle mattdowle May 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelChirico Please can you remove these 4 blank lines. The style in the file is that a group of tests like 2051.1 - 2051.6 should appear together as a block. (I was just doing that but since you're awake and making changes right now, otherwise I'm find to tidy things like that.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually yes, in this case, it's coverage tests & the file being covered is different (e.g. 2051.3 is from print.data.table.R while rleidv is from data.table.R). Doesn't feel like a new test number is needed but some visual space made sense. can revert though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nice single block of coverage tests to my eyes. Which is in an unrelated PR -- which is more to the point. In a wide-ranging very high line number PR like this, I was hoping to see there were no changes to tests at all. But then I saw there were changes to tests. But then I saw it was just a bit of extra coverage in a single block, so that's ok. That's the way I looked at it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, makes sense. The coverage stuff is because Codecov complained on first commit since the changes hit some uncovered lines so the patch diff failed, i.e., there's a reason I threw those tests into this PR in particular. So I took a pass at some lines that stuck out in a scan of the coverage diff.

I made sure to file the coverage stuff in a different commit, so in git history at least it's easier to see. But if anyone looks at this PR as a source, harder to figure out what's going on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see now, thanks. Makes perfect sense.

@MichaelChirico MichaelChirico changed the title remove most usages of <-" remove most usages of <- May 24, 2019
R/data.table.R Outdated Show resolved Hide resolved
mattdowle and others added 2 commits May 24, 2019 11:52
Co-Authored-By: Frank <franknarf1@users.noreply.github.com>
@mattdowle mattdowle merged commit 0530d01 into master May 24, 2019
@mattdowle mattdowle deleted the purge_arrow_assign branch May 24, 2019 22:33
mattdowle added a commit that referenced this pull request May 25, 2019
…n't have .Date and probably best not to use documented-internal .Date anyway
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

Successfully merging this pull request may close these issues.

Purge <- usage when not strictly necessary
3 participants