R For Dummies. Vries Andrie de
Чтение книги онлайн.
Читать онлайн книгу R For Dummies - Vries Andrie de страница 12
> paste <– paste("This gets","confusing")
> paste
[1] "This gets confusing"
> paste("Don’t","you","think?")
[1] "Don’t you think?"
R almost always will know perfectly well when you want the vector paste
and when you need the function paste()
. That doesn’t mean it’s a good idea to use the same name for both items, though. In some cases, doing so can cause unexpected errors. So if you can avoid giving the name of a function to an object, you should.
One situation in which you can really get into trouble is when you use capital
F
or T
as an object name. You can do it, but you’re likely to break code at some point. Although it’s a very bad idea, T
and F
are all too often used as abbreviations for TRUE
and FALSE
, respectively. But T
and F
are not reserved keywords. So, if you change them, R will first look for the object T
and only then try to replace T
with TRUE
. And any code that still expects T
to mean TRUE
will fail from this point on. Never use F
or T
, not as an object name and not as an abbreviation.
If you have experience in programming, you’ve probably heard of camel case before. Camel case is a way of giving longer names to objects and functions. You capitalize every first letter of a word that is part of the name to improve the readability. So, you can have a veryLongVariableName
and still be able to read it.
Unlike many other languages, R doesn’t use the dot (.) as an operator, so the dot can be used in names for objects as well. This style is called dotted style, where you write everything in lowercase and separate words or terms in a name with a dot. In fact, in R, many function names use dotted style. You’ve met a function like this earlier in the chapter: print.default()
. Some package authors also use an underscore instead of a dot.
print.default()
is the default method for the print()
function. You can find Information on the arguments of the Help page for print.default()
.
You’re not obligated to use dotted style; you can use whatever style you want. We use dotted style throughout this book for objects, and camel case for functions. R uses dotted style for many base functions and objects, but because some parts of the internal mechanisms of R rely on that dot, you’re safer using camel case for functions. Whenever you see a dot, though, you don’t have to wonder what it does – it’s just part of the name.
Конец ознакомительного фрагмента.
Текст предоставлен ООО «ЛитРес».
Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.
Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.