Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

r - What's the difference between identical(x, y) and isTRUE(all.equal(x, y))?

Is there any difference between testing isTRUE(all.equal(x, y)) and identical(x, y)?

The help page says:

Don't use 'all.equal' directly in 'if' expressions — either use 'isTRUE(all.equal(....))' or 'identical' if appropriate.

but that "if appropriate" leaves me in doubt. How do I decide which of the two is appropriate?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

all.equal tests for near equality, while identical is more exact (e.g. it has no tolerance for differences, and it compares storage type). From ?identical:

The function ‘all.equal’ is also sometimes used to test equality this way, but was intended for something different: it allows for small differences in numeric results.

And one reason you would wrap all.equal in isTRUE is because all.equal will report differences rather than simply return FALSE.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...