educative.io

What are/ why do we need "\n" and \n\n" with cat( ) function?

Why do we need the “\n” or “\n\n” with cat( )? When I run this code from the lesson:

cat(“Variables in the current directory: \n”)
ls() # returns all the variables created in the workspace
cat("\n")

cat(“Deleting myRealNumeric and myDecimalNumeric \n\n”)

rm(myRealNumeric, myDecimalNumeric) # delete the two mentioned variables

cat(“Variables in the current directory, now: \n”)
ls() # returns all the variables created in the workspace
** # myRealNumeric, myDecimalNumeric are now deleted**
cat("\n")

WITHOUT the "\n"s in them I seem to get the same result… what are they for?

Type your question above this line.

Course: https://www.educative.io/collection/10370001/5396243679281152
Lesson: https://www.educative.io/collection/page/10370001/5396243679281152/5088078450393088

Hi katie!
\n represents the carriage return in R. It helps to get us to the new line. You may also check it by inserting multiple \n in your code. You’ll see the difference.
I hope this helps. If you still have any confusion please let us know.
Thank you!