What does the expression !(...) mean?

Asked

Viewed 131 times

0

I couldn’t figure out what the expression means !(...)

Example:

if (!(book %in% books))
    stop("Unknown book")

2 answers

4


Anything you put inside an if("Anything") will be turned into true or false. The if body only executes if the result is true.

In your case as there is the character '!' indicates a negation of IF, ie "Not If"

Your expression is meaning:

If there is NO book (book) in the book collection (Books) do

Stop the expression execution and display a message (in your case will be: "Unknown book")

In short, your function is looking for a book in a list, and if not find returns a message.

2

It is a binary logic operator. It has the negation function, knowledge like not. It denies the return of the underlying term. If the return is verdadeiro the operator ! will yield the expression as falsa.

The language seems R.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.