From b2a2cbc32e3aee2a2cdf365aa6b4975a74f7474e Mon Sep 17 00:00:00 2001 From: Pedro Aphalo Date: Tue, 2 Apr 2024 20:29:50 +0300 Subject: [PATCH] Fix case of variable names --- R.as.calculator.Rnw | 2 +- appendixes.prj | 65 ++++++++------- appendixes.prj.bak | 65 ++++++++------- output/my-file.pdf | Bin 8197 -> 8197 bytes using-r-main-crc.tex | 188 +++++++++++++++++++++---------------------- 5 files changed, 164 insertions(+), 156 deletions(-) diff --git a/R.as.calculator.Rnw b/R.as.calculator.Rnw index 0c7aee18..f5ac1b85 100644 --- a/R.as.calculator.Rnw +++ b/R.as.calculator.Rnw @@ -119,7 +119,7 @@ vct1 + 1 print(vct1 + 1) @ \begin{playground} -There are some syntactically legal assignment statements that are not very frequently used, but you should be aware that they are valid, as they will not trigger error messages and may surprise you. The most important thing is to write code consistently. The ``backwards'' assignment operator \Roperator{->} and resulting code like \code{1 -> vct1}\index{assignment!leftwise} are valid but less frequently used. The use of the equals sign (\Roperator{=}) for assignment in place of \Roperator{<-} although valid is discouraged. Chaining\index{assignment!chaining} assignments as in the first statement below can be used to signal to the human reader that \code{vct1}, \code{vct2} and \code{vct3} are being assigned the same value. +There are some syntactically legal assignment statements that are not very frequently used, but you should be aware that they are valid, as they will not trigger error messages and may surprise you. The most important thing is to write code consistently. The ``backwards'' assignment operator \Roperator{->} and resulting code like \code{1 -> VCT1}\index{assignment!leftwise} are valid but less frequently used. The use of the equals sign (\Roperator{=}) for assignment in place of \Roperator{<-} although valid is discouraged. Chaining\index{assignment!chaining} assignments as in the first statement below can be used to signal to the human reader that \code{VCT1}, \code{VCT2} and \code{VCT3} are being assigned the same value. <>= VCT1 <- VCT2 <- VCT3 <- 0 diff --git a/appendixes.prj b/appendixes.prj index 6302ea31..a544dbf6 100644 --- a/appendixes.prj +++ b/appendixes.prj @@ -1,61 +1,61 @@ -41 Patch Control +36 Patch Control 1 1 1 -learn-r-2ed-crc.tex -35 -16 -1 +using-r-main-crc.Rnw +33 +15 +13 using-r-main-crc.Rnw TeX:RNW:UTF-8 -2 0 189 20 189 25 6074 -1 6522 208 1 1 458 435 1 906 254 255 -1 0 0 33 1 0 25 189 0 -1 0 -learn-r-2ed-crc.tex -TeX -403713275 2 -1 1125279 -1 1125282 152 152 1581 1098 1 1 484 2175 -1 -1 0 0 49 -1 -1 49 1 0 1125282 -1 0 -1 0 +134217730 0 189 20 189 25 6074 -1 6522 208 1 1 417 414 1 906 254 255 -1 0 0 33 1 0 25 189 0 -1 0 R.plotting.Rnw TeX:RNW:UNIX -17936379 2 -1 107594 -1 107597 380 380 1366 1438 1 1 354 667 -1 -1 0 0 115133 -1 -1 115133 1 0 107597 -1 0 -1 0 +17936379 2 -1 107594 -1 107597 380 380 1366 1438 1 1 321 667 -1 -1 0 0 115133 -1 -1 115133 1 0 107597 -1 0 -1 0 R.intro.Rnw TeX:RNW -17837307 1 -1 15642 -1 15662 228 228 1358 1175 1 1 1407 1218 -1 -1 0 0 30 -1 -1 30 1 0 15662 -1 0 -1 0 +17837307 1 -1 15642 -1 15662 228 228 1358 1175 1 1 1737 1035 -1 -1 0 0 30 -1 -1 30 1 0 15662 -1 0 -1 0 rbooks.bib BibTeX:UNIX -1147890 2 334 51 334 38 38 38 1429 959 1 1 627 667 -1 -1 0 0 1 1 1 1 1 0 38 334 0 -1 0 +1147890 2 334 51 334 38 38 38 1429 959 1 1 573 667 -1 -1 0 0 1 1 1 1 1 0 38 334 0 -1 0 preface.Rnw TeX:RNW -17838075 0 -1 7169 -1 8523 266 266 1252 1324 1 1 1277 841 -1 -1 0 0 18 -1 -1 18 1 0 8523 -1 0 -1 0 +17838075 0 -1 7169 -1 8523 266 266 1252 1324 1 1 1329 828 -1 -1 0 0 18 -1 -1 18 1 0 8523 -1 0 -1 0 R.data.containers.Rnw TeX:RNW:UNIX -17936379 0 -1 41150 -1 41147 190 190 1324 1242 1 1 601 667 -1 -1 0 0 83326 -1 -1 83326 3 0 41147 -1 1 0 -1 2 0 -1 0 -1 0 +17936379 0 -1 41150 -1 41147 190 190 1324 1242 1 1 549 667 -1 -1 0 0 83326 -1 -1 83326 3 0 41147 -1 1 0 -1 2 0 -1 0 -1 0 R.scripts.Rnw TeX:RNW:UNIX -17936379 0 -1 103139 -1 110879 152 152 1138 1210 1 1 1277 928 -1 -1 0 0 111412 -1 -1 111412 3 0 110879 -1 1 0 -1 2 27734 -1 0 -1 0 +17936379 0 -1 103139 -1 110879 152 152 1138 1210 1 1 1641 920 -1 -1 0 0 111412 -1 -1 111412 3 0 110879 -1 1 0 -1 2 27734 -1 0 -1 0 R.stats.rnw TeX:RNW:UNIX -17936379 0 -1 120590 -1 121394 418 418 1404 1476 1 1 432 986 -1 -1 0 0 128430 -1 -1 128430 1 0 121394 -1 0 -1 0 +17936379 0 -1 120590 -1 121394 418 418 1404 1476 1 1 1617 966 -1 -1 0 0 128430 -1 -1 128430 1 0 121394 -1 0 -1 0 R.data.io.Rnw TeX:RNW:UNIX -17936379 0 -1 75422 -1 75968 494 494 1480 1522 1 1 146 841 -1 -1 0 0 31 -1 -1 31 1 0 75968 -1 0 -1 0 +17936379 0 -1 75422 -1 75968 494 494 1480 1522 1 1 129 828 -1 -1 0 0 31 -1 -1 31 1 0 75968 -1 0 -1 0 usingr.sty TeX:STY:UNIX -1158386 2 118 14 118 23 190 190 1176 1248 1 0 411 667 -1 -1 0 0 1 1 1 1 1 0 23 118 0 0 0 +1158386 2 118 14 118 23 190 190 1176 1248 1 0 376 667 -1 -1 0 0 1 1 1 1 1 0 23 118 0 0 0 R.data.Rnw TeX:RNW:UNIX -17936379 0 -1 15514 -1 15553 342 342 1328 1400 1 1 848 1044 -1 -1 0 0 31 -1 -1 31 1 0 15553 -1 0 -1 0 +17936379 0 -1 15514 -1 15553 342 342 1328 1400 1 1 1101 1035 -1 -1 0 0 31 -1 -1 31 1 0 15553 -1 0 -1 0 references.bib BibTeX:UNIX -1147890 2 438 34 438 21 76 76 1467 997 1 1 406 667 -1 -1 0 0 1 1 1 1 1 0 21 438 0 -1 0 +1147890 2 438 34 438 21 76 76 1467 997 1 1 369 667 -1 -1 0 0 1 1 1 1 1 0 21 438 0 -1 0 R.functions.Rnw TeX:RNW:UNIX -17936379 0 -1 43565 -1 43566 456 456 1442 1484 1 1 640 870 -1 -1 0 0 31 -1 -1 31 1 0 43566 -1 0 -1 0 +17936379 0 -1 43565 -1 43566 456 456 1442 1484 1 1 2133 851 -1 -1 0 0 31 -1 -1 31 1 0 43566 -1 0 -1 0 R.as.calculator.Rnw TeX:RNW:UNIX -17936379 0 -1 72277 -1 72285 190 190 1324 1242 1 1 1433 290 -1 -1 0 0 31 -1 -1 31 4 0 72285 -1 1 147834 -1 2 20226 -1 3 56017 -1 0 -1 0 +286371835 0 -1 10678 -1 10681 190 190 1324 1242 1 1 729 506 -1 -1 0 0 31 -1 -1 31 4 0 10681 -1 1 147834 -1 2 20226 -1 3 56017 -1 0 -1 0 R.learning.Rnw TeX:UK -17837307 0 -1 23277 -1 23277 190 190 1320 1137 1 1 393 1334 -1 -1 0 0 41 1 1 41 1 0 23277 -1 0 -1 0 +17837307 0 -1 23277 -1 23277 190 190 1320 1137 1 1 357 2093 -1 -1 0 0 41 1 1 41 1 0 23277 -1 0 -1 0 +learn-r-2ed-crc.tex +TeX +403713275 2 -1 1125279 -1 1125282 152 152 1581 1098 1 1 1965 1265 -1 -1 0 0 49 -1 -1 49 1 0 1125282 -1 0 -1 0 using-r-main-crc.tex TeX 269495547 0 -1 729593 -1 729785 152 152 1581 1098 1 1 302 377 -1 -1 0 0 49 -1 -1 49 1 0 729785 -1 0 -1 0 @@ -80,12 +80,6 @@ TeX using-r-main-crc.ind TeX:AUX:UNIX 269594610 8 366 1 365 1 308 308 1684 1215 1 0 125 870 -1 -1 0 0 17 0 0 17 1 0 1 365 0 0 0 -F:\aphalo\references\all_references_dedup.bib -BibTeX -269484274 0 155348 1 155348 1 228 228 1256 1174 1 1 146 667 -1 -1 0 0 20 0 0 20 1 0 1 155348 0 -1 0 -:\Program Files\MiKTeX\tex\generic\babel\babel.sty -TeX:STY:UNIX -269593842 7 4282 1 4282 17 152 152 1180 1098 1 0 333 1189 -1 -1 0 0 -1 -1 -1 -1 1 0 17 4282 0 0 0 krantz.cls TeX:STY:UNIX 269594610 1 194 1 194 36 76 76 1062 1134 1 0 580 -10208 -1 -1 0 0 3 0 0 3 1 0 36 194 0 0 0 @@ -114,8 +108,19 @@ R.as.calculator.tex TeX 269496315 0 -1 0 -1 0 76 76 1769 997 1 1 148 0 -1 -1 0 0 -1 -1 -1 -1 1 0 0 -1 0 0 0 -*learn-r-2ed-crc.tex +*using-r-main-crc.Rnw > *rbooks.bib *references.bib +*preface.Rnw +*R.learning.Rnw +*R.intro.Rnw +*R.as.calculator.Rnw +*R.data.containers.Rnw +*R.scripts.Rnw +*R.functions.Rnw +*R.stats.Rnw +*R.data.Rnw +*R.plotting.Rnw +*R.data.io.Rnw < diff --git a/appendixes.prj.bak b/appendixes.prj.bak index 4864bc71..d8ceaa0e 100644 --- a/appendixes.prj.bak +++ b/appendixes.prj.bak @@ -1,61 +1,61 @@ -41 Patch Control +36 Patch Control 1 1 1 -learn-r-2ed-crc.tex -35 -16 -1 +using-r-main-crc.Rnw +33 +15 +0 using-r-main-crc.Rnw TeX:RNW:UTF-8 -2 0 189 20 189 25 6074 -1 6522 208 1 1 458 435 1 906 254 255 -1 0 0 33 1 0 25 189 0 -1 0 -learn-r-2ed-crc.tex -TeX -403713275 2 -1 1125279 -1 1125282 152 152 1581 1098 1 1 484 435 -1 -1 0 0 49 -1 -1 49 1 0 1125282 -1 0 -1 0 +402653186 0 189 20 189 25 6074 -1 6522 208 1 1 417 414 1 906 254 255 -1 0 0 33 1 0 25 189 0 -1 0 R.plotting.Rnw TeX:RNW:UNIX -17936379 2 -1 107594 -1 107597 380 380 1366 1438 1 1 354 667 -1 -1 0 0 115133 -1 -1 115133 1 0 107597 -1 0 -1 0 +17936379 2 -1 107594 -1 107597 380 380 1366 1438 1 1 321 667 -1 -1 0 0 115133 -1 -1 115133 1 0 107597 -1 0 -1 0 R.intro.Rnw TeX:RNW -17837307 1 -1 15642 -1 15662 228 228 1358 1175 1 1 1407 1218 -1 -1 0 0 30 -1 -1 30 1 0 15662 -1 0 -1 0 +17837307 1 -1 15642 -1 15662 228 228 1358 1175 1 1 1737 1035 -1 -1 0 0 30 -1 -1 30 1 0 15662 -1 0 -1 0 rbooks.bib BibTeX:UNIX -1147890 2 334 51 334 38 38 38 1429 959 1 1 627 667 -1 -1 0 0 1 1 1 1 1 0 38 334 0 -1 0 +1147890 2 334 51 334 38 38 38 1429 959 1 1 573 667 -1 -1 0 0 1 1 1 1 1 0 38 334 0 -1 0 preface.Rnw TeX:RNW -17838075 0 -1 7169 -1 8523 266 266 1252 1324 1 1 1277 841 -1 -1 0 0 18 -1 -1 18 1 0 8523 -1 0 -1 0 +17838075 0 -1 7169 -1 8523 266 266 1252 1324 1 1 1329 828 -1 -1 0 0 18 -1 -1 18 1 0 8523 -1 0 -1 0 R.data.containers.Rnw TeX:RNW:UNIX -17936379 0 -1 41150 -1 41147 190 190 1324 1242 1 1 601 667 -1 -1 0 0 83326 -1 -1 83326 3 0 41147 -1 1 0 -1 2 0 -1 0 -1 0 +17936379 0 -1 41150 -1 41147 190 190 1324 1242 1 1 549 667 -1 -1 0 0 83326 -1 -1 83326 3 0 41147 -1 1 0 -1 2 0 -1 0 -1 0 R.scripts.Rnw TeX:RNW:UNIX -17936379 0 -1 103139 -1 110879 152 152 1138 1210 1 1 1277 928 -1 -1 0 0 111412 -1 -1 111412 3 0 110879 -1 1 0 -1 2 27734 -1 0 -1 0 +17936379 0 -1 103139 -1 110879 152 152 1138 1210 1 1 1641 920 -1 -1 0 0 111412 -1 -1 111412 3 0 110879 -1 1 0 -1 2 27734 -1 0 -1 0 R.stats.rnw TeX:RNW:UNIX -17936379 0 -1 120590 -1 121394 418 418 1404 1476 1 1 432 986 -1 -1 0 0 128430 -1 -1 128430 1 0 121394 -1 0 -1 0 +17936379 0 -1 120590 -1 121394 418 418 1404 1476 1 1 1617 966 -1 -1 0 0 128430 -1 -1 128430 1 0 121394 -1 0 -1 0 R.data.io.Rnw TeX:RNW:UNIX -17936379 0 -1 75422 -1 75968 494 494 1480 1522 1 1 146 841 -1 -1 0 0 31 -1 -1 31 1 0 75968 -1 0 -1 0 +17936379 0 -1 75422 -1 75968 494 494 1480 1522 1 1 129 828 -1 -1 0 0 31 -1 -1 31 1 0 75968 -1 0 -1 0 usingr.sty TeX:STY:UNIX -1158386 2 118 14 118 23 190 190 1176 1248 1 0 411 667 -1 -1 0 0 1 1 1 1 1 0 23 118 0 0 0 +1158386 2 118 14 118 23 190 190 1176 1248 1 0 376 667 -1 -1 0 0 1 1 1 1 1 0 23 118 0 0 0 R.data.Rnw TeX:RNW:UNIX -17936379 0 -1 15514 -1 15553 342 342 1328 1400 1 1 848 1044 -1 -1 0 0 31 -1 -1 31 1 0 15553 -1 0 -1 0 +17936379 0 -1 15514 -1 15553 342 342 1328 1400 1 1 1101 1035 -1 -1 0 0 31 -1 -1 31 1 0 15553 -1 0 -1 0 references.bib BibTeX:UNIX -1147890 2 438 34 438 21 76 76 1467 997 1 1 406 667 -1 -1 0 0 1 1 1 1 1 0 21 438 0 -1 0 +1147890 2 438 34 438 21 76 76 1467 997 1 1 369 667 -1 -1 0 0 1 1 1 1 1 0 21 438 0 -1 0 R.functions.Rnw TeX:RNW:UNIX -17936379 0 -1 43565 -1 43566 456 456 1442 1484 1 1 640 870 -1 -1 0 0 31 -1 -1 31 1 0 43566 -1 0 -1 0 +17936379 0 -1 43565 -1 43566 456 456 1442 1484 1 1 2133 851 -1 -1 0 0 31 -1 -1 31 1 0 43566 -1 0 -1 0 R.as.calculator.Rnw TeX:RNW:UNIX -17936379 0 -1 72277 -1 72285 190 190 1324 1242 1 1 1433 290 -1 -1 0 0 31 -1 -1 31 4 0 72285 -1 1 147834 -1 2 20226 -1 3 56017 -1 0 -1 0 +17936379 0 -1 72277 -1 72285 190 190 1324 1242 1 1 1569 276 -1 -1 0 0 31 -1 -1 31 4 0 72285 -1 1 147834 -1 2 20226 -1 3 56017 -1 0 -1 0 R.learning.Rnw TeX:UK -17837307 0 -1 23277 -1 23277 190 190 1320 1137 1 1 393 1334 -1 -1 0 0 41 1 1 41 1 0 23277 -1 0 -1 0 +17837307 0 -1 23277 -1 23277 190 190 1320 1137 1 1 357 2093 -1 -1 0 0 41 1 1 41 1 0 23277 -1 0 -1 0 +learn-r-2ed-crc.tex +TeX +403713275 2 -1 1125279 -1 1125282 152 152 1581 1098 1 1 1965 1265 -1 -1 0 0 49 -1 -1 49 1 0 1125282 -1 0 -1 0 using-r-main-crc.tex TeX 269495547 0 -1 729593 -1 729785 152 152 1581 1098 1 1 302 377 -1 -1 0 0 49 -1 -1 49 1 0 729785 -1 0 -1 0 @@ -80,12 +80,6 @@ TeX using-r-main-crc.ind TeX:AUX:UNIX 269594610 8 366 1 365 1 308 308 1684 1215 1 0 125 870 -1 -1 0 0 17 0 0 17 1 0 1 365 0 0 0 -F:\aphalo\references\all_references_dedup.bib -BibTeX -269484274 0 155348 1 155348 1 228 228 1256 1174 1 1 146 667 -1 -1 0 0 20 0 0 20 1 0 1 155348 0 -1 0 -:\Program Files\MiKTeX\tex\generic\babel\babel.sty -TeX:STY:UNIX -269593842 7 4282 1 4282 17 152 152 1180 1098 1 0 333 1189 -1 -1 0 0 -1 -1 -1 -1 1 0 17 4282 0 0 0 krantz.cls TeX:STY:UNIX 269594610 1 194 1 194 36 76 76 1062 1134 1 0 580 -10208 -1 -1 0 0 3 0 0 3 1 0 36 194 0 0 0 @@ -114,8 +108,19 @@ R.as.calculator.tex TeX 269496315 0 -1 0 -1 0 76 76 1769 997 1 1 148 0 -1 -1 0 0 -1 -1 -1 -1 1 0 0 -1 0 0 0 -*learn-r-2ed-crc.tex +*using-r-main-crc.Rnw > *rbooks.bib *references.bib +*preface.Rnw +*R.learning.Rnw +*R.intro.Rnw +*R.as.calculator.Rnw +*R.data.containers.Rnw +*R.scripts.Rnw +*R.functions.Rnw +*R.stats.Rnw +*R.data.Rnw +*R.plotting.Rnw +*R.data.io.Rnw < diff --git a/output/my-file.pdf b/output/my-file.pdf index 5609ff3f1cfa7dacc71c34cffc9952f88df160e9..5bb33a5435dd3a8796fd1fd51e4ab93d8a33f586 100644 GIT binary patch delta 48 wcmZp5XmyxirfO_tW@uz+X>6#;rSF@c;*waBs-WRwWn^GvVgQ%h7`;j!05+lwp#T5? delta 48 wcmZp5XmyxirfOtpZe(O^YG|R!rSF@c;*waBs-WRwWn^GvVgQ%h7`;j!05=2-rvLx| diff --git a/using-r-main-crc.tex b/using-r-main-crc.tex index 6584d0b7..e56a42af 100644 --- a/using-r-main-crc.tex +++ b/using-r-main-crc.tex @@ -159,16 +159,16 @@ \chapter*{Preface} Using a language actively is the most efficient way of learning it. By using it, I mean actually reading, writing, and running scripts or programs. \emph{Learn R: As a Language} supports learning the \Rlang language in a way comparable to how children learn to speak: they work out what the rules are, simply by listening to people speak and trying to utter what they want to tell their parents. Of course, small children also receive guidance through feedback, but they are not taught a prescriptive set of rules like when learning a second language at school. Instead of listening, readers will read and run code, and instead of speaking, readers will write and try to run \Rlang-language code on a computer. I do provide explanations and guidance, as understanding how \Rlang works greatly helps with its use. However, the approach I encourage in this book is for readers to play with the numerous examples and to create variations upon them, to find out by themselves the patterns behind the \Rlang language. Instead of parents being the sounding board for the first utterances of readers new to \Rlang, the computer will play this role. Although working through the examples in \emph{Learn R: As a Language} in a group of peers or in class is beneficial, the book is designed to be useful also in the absence of such support. -\paragraph*{Changes in the second edition.} I edited the text from the first edition to correct all errors and outdated examples or explanations known to me. This revised second edition reflects changes in \Rlang and the contributed packages used in the book. Very little of the code from the first edition had stopped working but deprecations meant that a few examples triggered messages or warnings, and will eventually fail. Recent ($>$\,4.0.0) versions of \Rlang have significant enhancements including the new pipe operator described and used in this second edition. Packages have also evolved acquiring new features like a new approach to flipping plots in \pkgname{ggplot2}. +\paragraph*{Changes in the second edition:} I edited the text from the first edition to correct all errors and outdated examples or explanations known to me. This revised second edition reflects changes in \Rlang and the contributed packages used in the book. Very little of the code from the first edition had stopped working but deprecations meant that a few examples triggered messages or warnings, and will eventually fail. Recent ($>$\,4.0.0) versions of \Rlang have significant enhancements, including the new pipe operator described and used in this second edition. Packages have also evolved, acquiring new features like a new approach to flipping plots in \pkgname{ggplot2}. I have aimed at making the book more accessible to readers with no previous experience in computer programming. Feedback from readers and reviewers highlighted a few gaps in the content and some difficult-to-follow explanations. I revised the text, in some cases changing the sequence of presentation. I added diagrams to illustrate the structure of different types of objects and flowcharts to describe how program constructs work. I added tables listing groups of related functions. New sections cover character string operations, and details of data wrangling in \Rlang. Some of the most frequently asked questions about \Rlang are answered in the text and separately indexed. All exercises or ``playgrounds'' are numbered to facilitate their use as class work and the sharing of model answers. As the first edition has been frequently found useful as a reference, I expanded the already thorough indexing and added more cross-references connecting related sections across the whole book. An additional change is in my view about packages \pkgnameNI{dplyr} and \pkgnameNI{tidyr}, part of the \pkgname{tidyverse}. I have come to think that the rate of development of these two packages can make them difficult for users for whom data analysis is just one aspect of their occupation. As these packages are widely used, I emphasise more than in the first edition the differences between functions and classes from packages \pkgnameNI{dplyr} and \pkgnameNI{tidyr} and equivalent ones from base \Rlang. I added a section on working with dates and times using the \pkgnameNI{lubridate} package. I updated and reorganised the chapter describing package \pkgname{ggplot2} and some of its extensions. -In numbers, the page count has increased by 27\%, the number of figures from eight to twenty six plus nine in-text diagrams, and tables from none to seven. As for the design, text boxes have been replaced by call-outs marked with marginal bars. In addition, starting from version 2.0.0, the \pkgname{learnrbook} package supports the first and second editions of the book. It contains data, scripts, and all the code examples from both editions. It also helps with the installation of all the packages used in the book. The website at \url{https://www.learnr-book.info/} provides updated open-access content. +In numbers, the page count has increased by 27\%, the number of figures from eight to twenty-six plus nine in-text diagrams, and tables from none to seven. As for the design, text boxes have been replaced by call-outs marked with marginal bars. In addition, starting from version 2.0.0, the \pkgname{learnrbook} package supports the first and second editions of the book. It contains data, scripts, and all the code examples from both editions. It also helps with the installation of all the packages used in the book. The website at \url{https://www.learnr-book.info/} provides updated open-access content. \section*{Acknowledgements} -I thank Jaakko Heinonen for introducing me in the late 1990s to the then new \Rlang. Along the way many experts have answered my questions in usenet and more recently in \stackoverflow. I wish to warmly thank members of my research group, students, collaborators, authors of books, and people I have met online or at conferences. They have made it possible for me to write this book. I am specially indebted to Dan Yavorsky, Tarja Lehto, Titta Kotilainen, Tautvydas Zalnierius, Fang Wang, Yan Yan, Neha Rai, Markus Laurel, Brett Cooper, Viivi Lindholm, Mat\v{e}j Rzehulka, Zuzana Svarna, colleagues, students, and anonymous reviewers for many very helpful comments on the draft manuscript and/or the first edition. Rob Calver, editor of both editions, provided advice and encouragement with great patience, Paul Boyd, Shashi Kumar, Ashraf Reza, Vaishali Singh, Lara Spieker, and Sherry Thomas efficiently helped with different aspects of this project. +I thank Jaakko Heinonen for introducing me in the late 1990s to the then new \Rlang. Along the way many experts have answered my questions in usenet and more recently in \stackoverflow. I wish to warmly thank members of my research group, students, collaborators, authors of books, and people I have met online or at conferences. They have made it possible for me to write this book. I am specially indebted to Dan Yavorsky, Tarja Lehto, Titta Kotilainen, Tautvydas Zalnierius, Fang Wang, Yan Yan, Neha Rai, Markus Laurel, Brett Cooper, Viivi Lindholm, Mat\v{e}j Rzehulka, Zuzana Svarna, colleagues, students, and anonymous reviewers for many very helpful comments on the draft manuscript and/or the first edition. Rob Calver, editor of both editions, provided advice and encouragement with great patience. Paul Boyd, Shashi Kumar, Ashraf Reza, Vaishali Singh, Lara Spieker, and Sherry Thomas efficiently helped with different aspects of this project. The writing of this second edition was helped by a six-month sabbatical granted by the Faculty of Biological and Environmental Sciences of the University of Helsinki, Finland. I thank Prof.\ Kurt Fagerstedt for his support. @@ -792,7 +792,7 @@ \section{Numeric Values and Arithmetic}\label{sec:calc:numeric} \end{kframe} \end{knitrout} \begin{playground} -There are some syntactically legal assignment statements that are not very frequently used, but you should be aware that they are valid, as they will not trigger error messages and may surprise you. The most important thing is to write code consistently. The ``backwards'' assignment operator \Roperator{->} and resulting code like \code{1 -> vct1}\index{assignment!leftwise} are valid but less frequently used. The use of the equals sign (\Roperator{=}) for assignment in place of \Roperator{<-} although valid is discouraged. Chaining\index{assignment!chaining} assignments as in the first statement below can be used to signal to the human reader that \code{vct1}, \code{vct2} and \code{vct3} are being assigned the same value. +There are some syntactically legal assignment statements that are not very frequently used, but you should be aware that they are valid, as they will not trigger error messages and may surprise you. The most important thing is to write code consistently. The ``backwards'' assignment operator \Roperator{->} and resulting code like \code{1 -> VCT1}\index{assignment!leftwise} are valid but less frequently used. The use of the equals sign (\Roperator{=}) for assignment in place of \Roperator{<-} although valid is discouraged. Chaining\index{assignment!chaining} assignments as in the first statement below can be used to signal to the human reader that \code{VCT1}, \code{VCT2} and \code{VCT3} are being assigned the same value. \begin{knitrout}\footnotesize \definecolor{shadecolor}{rgb}{0.98, 0.98, 0.98}\color{fgcolor}\begin{kframe} @@ -8428,14 +8428,14 @@ \section{Reshaping and Editing Data Frames}\label{sec:calc:reshape} \end{alltt} \begin{verbatim} ## id Time Weight Height -## 1 1 Before 21.05859 10.57587 -## 2 1 After 29.57182 14.15418 -## 3 2 Before 21.52375 10.12694 -## 4 2 After 30.15447 14.91599 -## 5 3 Before 21.05859 10.57587 -## 6 3 After 29.57182 14.15418 -## 7 4 Before 21.52375 10.12694 -## 8 4 After 30.15447 14.91599 +## 1 1 Before 20.25205 9.72346 +## 2 1 After 31.38053 14.74530 +## 3 2 Before 19.31199 11.14205 +## 4 2 After 29.73201 15.14966 +## 5 3 Before 20.25205 9.72346 +## 6 3 After 31.38053 14.74530 +## 7 4 Before 19.31199 11.14205 +## 8 4 After 29.73201 15.14966 \end{verbatim} \begin{alltt} \hlcom{# make it wider} @@ -8444,10 +8444,10 @@ \section{Reshaping and Editing Data Frames}\label{sec:calc:reshape} \end{alltt} \begin{verbatim} ## id Weight.Before Height.Before Weight.After Height.After -## 1 1 21.05859 10.57587 29.57182 14.15418 -## 3 2 21.52375 10.12694 30.15447 14.91599 -## 5 3 21.05859 10.57587 29.57182 14.15418 -## 7 4 21.52375 10.12694 30.15447 14.91599 +## 1 1 20.25205 9.72346 31.38053 14.74530 +## 3 2 19.31199 11.14205 29.73201 15.14966 +## 5 3 20.25205 9.72346 31.38053 14.74530 +## 7 4 19.31199 11.14205 29.73201 15.14966 \end{verbatim} \begin{alltt} \hlcom{# possible further calculation} @@ -8459,15 +8459,15 @@ \section{Reshaping and Editing Data Frames}\label{sec:calc:reshape} \end{alltt} \begin{verbatim} ## id Weight.Before Height.Before Weight.After Height.After Weight.growth -## 1 1 21.05859 10.57587 29.57182 14.15418 8.513234 -## 3 2 21.52375 10.12694 30.15447 14.91599 8.630720 -## 5 3 21.05859 10.57587 29.57182 14.15418 8.513234 -## 7 4 21.52375 10.12694 30.15447 14.91599 8.630720 +## 1 1 20.25205 9.72346 31.38053 14.74530 11.12849 +## 3 2 19.31199 11.14205 29.73201 15.14966 10.42002 +## 5 3 20.25205 9.72346 31.38053 14.74530 11.12849 +## 7 4 19.31199 11.14205 29.73201 15.14966 10.42002 ## Height.growth -## 1 3.578307 -## 3 4.789053 -## 5 3.578307 -## 7 4.789053 +## 1 5.021842 +## 3 4.007614 +## 5 5.021842 +## 7 4.007614 \end{verbatim} \end{kframe} \end{knitrout} @@ -8489,22 +8489,22 @@ \section{Reshaping and Editing Data Frames}\label{sec:calc:reshape} \end{alltt} \begin{verbatim} ## id Time ID Quantity Value -## 1.Weight 1 Before 1 Weight 21.05859 -## 2.Weight 1 After 2 Weight 29.57182 -## 3.Weight 2 Before 3 Weight 21.52375 -## 4.Weight 2 After 4 Weight 30.15447 -## 5.Weight 3 Before 5 Weight 21.05859 -## 6.Weight 3 After 6 Weight 29.57182 -## 7.Weight 4 Before 7 Weight 21.52375 -## 8.Weight 4 After 8 Weight 30.15447 -## 1.Height 1 Before 1 Height 10.57587 -## 2.Height 1 After 2 Height 14.15418 -## 3.Height 2 Before 3 Height 10.12694 -## 4.Height 2 After 4 Height 14.91599 -## 5.Height 3 Before 5 Height 10.57587 -## 6.Height 3 After 6 Height 14.15418 -## 7.Height 4 Before 7 Height 10.12694 -## 8.Height 4 After 8 Height 14.91599 +## 1.Weight 1 Before 1 Weight 20.25205 +## 2.Weight 1 After 2 Weight 31.38053 +## 3.Weight 2 Before 3 Weight 19.31199 +## 4.Weight 2 After 4 Weight 29.73201 +## 5.Weight 3 Before 5 Weight 20.25205 +## 6.Weight 3 After 6 Weight 31.38053 +## 7.Weight 4 Before 7 Weight 19.31199 +## 8.Weight 4 After 8 Weight 29.73201 +## 1.Height 1 Before 1 Height 9.72346 +## 2.Height 1 After 2 Height 14.74530 +## 3.Height 2 Before 3 Height 11.14205 +## 4.Height 2 After 4 Height 15.14966 +## 5.Height 3 Before 5 Height 9.72346 +## 6.Height 3 After 6 Height 14.74530 +## 7.Height 4 Before 7 Height 11.14205 +## 8.Height 4 After 8 Height 15.14966 \end{verbatim} \end{kframe} \end{knitrout} @@ -9679,12 +9679,12 @@ \section{Data Pipes}\label{sec:script:pipes} \hlkwd{subset}\hlstd{(}\hlkwc{x} \hlstd{= _, is.large)} \end{alltt} \begin{verbatim} -## x y is.large x4 -## 6 6 0.24821983 TRUE 1296 -## 7 7 -1.32684062 TRUE 2401 -## 8 8 -0.05789719 TRUE 4096 -## 9 9 0.29258553 TRUE 6561 -## 10 10 -0.63177298 TRUE 10000 +## x y is.large x4 +## 6 6 -1.4469043 TRUE 1296 +## 7 7 -2.8523268 TRUE 2401 +## 8 8 -1.3707442 TRUE 4096 +## 9 9 -0.3188003 TRUE 6561 +## 10 10 -1.9258181 TRUE 10000 \end{verbatim} \end{kframe} \end{knitrout} @@ -9718,11 +9718,11 @@ \section{Data Pipes}\label{sec:script:pipes} \end{alltt} \begin{verbatim} ## y is.large x4 -## 6 0.37246559 TRUE 1296 -## 7 0.94549288 TRUE 2401 -## 8 1.06913611 TRUE 4096 -## 9 -0.06230746 TRUE 6561 -## 10 -0.47022979 TRUE 10000 +## 6 -0.54798093 TRUE 1296 +## 7 -0.04988366 TRUE 2401 +## 8 0.53896237 TRUE 4096 +## 9 -0.45819248 TRUE 6561 +## 10 0.32065978 TRUE 10000 \end{verbatim} \end{kframe} \end{knitrout} @@ -9739,17 +9739,17 @@ \section{Data Pipes}\label{sec:script:pipes} \hlkwd{subset}\hlstd{(}\hlkwc{x} \hlstd{= _,} \hlkwc{select} \hlstd{=} \hlkwd{c}\hlstd{(y, x4))} \end{alltt} \begin{verbatim} -## y x4 -## 1 -0.92142448 1 -## 2 0.62913424 16 -## 3 0.42764317 81 -## 4 0.04825671 256 -## 5 0.56229201 625 -## 6 -3.73168145 1296 -## 7 0.16993802 2401 -## 8 -0.40038974 4096 -## 9 -0.80676551 6561 -## 10 0.13977301 10000 +## y x4 +## 1 -0.8676710 1 +## 2 -0.2482889 16 +## 3 0.4253464 81 +## 4 0.0740767 256 +## 5 -1.0535927 625 +## 6 0.1942226 1296 +## 7 0.1554477 2401 +## 8 -1.7877933 4096 +## 9 0.3365538 6561 +## 10 -1.1224213 10000 \end{verbatim} \end{kframe} \end{knitrout} @@ -9763,9 +9763,9 @@ \section{Data Pipes}\label{sec:script:pipes} \hlkwd{aggregate}\hlstd{(}\hlkwc{data} \hlstd{= _, y} \hlopt{~} \hlstd{group, mean)} \end{alltt} \begin{verbatim} -## group y -## 1 T1 -0.2764033 -## 2 T2 0.3205809 +## group y +## 1 T1 1.0559190 +## 2 T2 0.9519729 \end{verbatim} \end{kframe} \end{knitrout} @@ -9782,7 +9782,7 @@ \section{Data Pipes}\label{sec:script:pipes} \hlstd{_[[}\hlstr{"y"}\hlstd{]]} \end{alltt} \begin{verbatim} -## [1] -0.2216849 -0.7040829 +## [1] 0.5414433 0.2160888 \end{verbatim} \end{kframe} \end{knitrout} @@ -12036,7 +12036,7 @@ \subsection{Ordinary functions}\label{sec:functions:sem}\label{sec:ordinary:func ## } ## sqrt(var(x)/length(x)) ## } -## +## \end{verbatim} \end{kframe} \end{knitrout} @@ -12052,7 +12052,7 @@ \subsection{Ordinary functions}\label{sec:functions:sem}\label{sec:ordinary:func ## function (x, na.rm = FALSE) ## sqrt(var(if (is.vector(x) || is.factor(x)) x else as.double(x), ## na.rm = na.rm)) -## +## ## \end{verbatim} \end{kframe} @@ -12189,7 +12189,7 @@ \section{Objects, Classes and Methods}\label{sec:script:objects:classes:methods} \begin{verbatim} ## function (x, ...) ## UseMethod("mean") -## +## ## \end{verbatim} \end{kframe} @@ -12381,7 +12381,7 @@ \subsection{Sharing of \Rlang-language extensions} In a ``source package'', the code written in \Rlang, and possibly in other programming languages, is contained in text files that are compressed together into a single archive file. In a ``binary package'' the source code is already processed into a form suitable for faster installation. Binary package files are specific to each major version of \Rlang, operating system, and computer architecture. In addition to being slower, package installation from sources can requires additional software, such as compilers. A compiler translates the text representation of a computer program written in \Clang, \Cpplang, \langname{FORTRAN}, etc., into machine code, i.e., instructions for the computer hardware. \Rlang code is compiled into instructions for a virtual machine, part of \Rlang, that does the final translation into machine code at runtime. \end{explainbox} -For distribution, a single compressed archive file is used for aech package. Packages can be shared as source- or binary-code files, sent for example through e-mail. However, the largest public repository of \Rpgrm packages is called \CRAN (\url{https://cran.r-project.org/}), an acronym for Comprehensive R Archive Network. Packages available through \CRAN are guaranteed to work, in the sense of not failing any tests built into the packages and not crashing or aborting prematurely. They are tested daily, as they may depend on other packages whose code will change when updated. The number of packages available through \CRAN at the time of printing (2024-02-17) was \ensuremath{2.04\times 10^{4}}. +For distribution, a single compressed archive file is used for aech package. Packages can be shared as source- or binary-code files, sent for example through e-mail. However, the largest public repository of \Rpgrm packages is called \CRAN (\url{https://cran.r-project.org/}), an acronym for Comprehensive R Archive Network. Packages available through \CRAN are guaranteed to work, in the sense of not failing any tests built into the packages and not crashing or aborting prematurely. They are tested daily, as they may depend on other packages whose code will change when updated. The number of packages available through \CRAN at the time of printing (2024-03-26) was \ensuremath{2.06\times 10^{4}}. A key repository for bioinformatics with \Rlang is Bioconductor\index{Bioconductor} (\url{https://www.bioconductor.org/}), containing packages that pass strict quality tests, adding an additional 3\,400 packages. rOpenScience\index{rOpenScience} has established guidelines and a system for code peer review for \Rlang packages. These peer-reviewed packages are available through \CRAN or other repositories and listed at the rOpenScience website (\url{https://ropensci.org/}). Occasionally, one may have, or want, to install packages or updates that are not yet in \CRAN, either from the R Universe (\url{https://r-universe.dev/}) repositories, or from Git repositories (e.g., from GitHub). @@ -12601,7 +12601,7 @@ \subsection{How packages work}\label{sec:packages:work} \begin{verbatim} ## function (x, ...) ## UseMethod("mean") -## +## ## \end{verbatim} \end{kframe} @@ -17629,7 +17629,7 @@ \section{Times and Dates with \pkgname{lubridate}}\label{sec:data:datetime} \hlkwd{as.POSIXct}\hlstd{(this.day,} \hlkwc{tz} \hlstd{=} \hlstr{""}\hlstd{)} \hlcom{# local time zone} \end{alltt} \begin{verbatim} -## [1] "2024-02-17 02:00:00 EET" +## [1] "2024-03-26 02:00:00 EET" \end{verbatim} \end{kframe} \end{knitrout} @@ -17649,7 +17649,7 @@ \section{Times and Dates with \pkgname{lubridate}}\label{sec:data:datetime} \hlstd{this.instant} \end{alltt} \begin{verbatim} -## [1] "2024-02-17 22:35:30 EET" +## [1] "2024-03-26 12:19:46 EET" \end{verbatim} \end{kframe} \end{knitrout} @@ -17780,7 +17780,7 @@ \section{Times and Dates with \pkgname{lubridate}}\label{sec:data:datetime} \hlstd{my.time} \end{alltt} \begin{verbatim} -## [1] "2024-02-17 22:35:30 EET" +## [1] "2024-03-26 12:19:46 EET" \end{verbatim} \begin{alltt} \hlkwd{year}\hlstd{(my.time)} @@ -17792,13 +17792,13 @@ \section{Times and Dates with \pkgname{lubridate}}\label{sec:data:datetime} \hlkwd{hour}\hlstd{(my.time)} \end{alltt} \begin{verbatim} -## [1] 22 +## [1] 12 \end{verbatim} \begin{alltt} \hlkwd{second}\hlstd{(my.time)} \end{alltt} \begin{verbatim} -## [1] 30.9487 +## [1] 46.88581 \end{verbatim} \begin{alltt} \hlkwd{second}\hlstd{(my.time)} \hlkwb{<-} \hlnum{0} @@ -17814,13 +17814,13 @@ \section{Times and Dates with \pkgname{lubridate}}\label{sec:data:datetime} \hlkwd{trunc}\hlstd{(my.time,} \hlstr{"days"}\hlstd{)} \end{alltt} \begin{verbatim} -## [1] "2024-02-17 EET" +## [1] "2024-03-26 EET" \end{verbatim} \begin{alltt} \hlkwd{round}\hlstd{(my.time,} \hlstr{"hours"}\hlstd{)} \end{alltt} \begin{verbatim} -## [1] "2024-02-17 23:00:00 EET" +## [1] "2024-03-26 12:00:00 EET" \end{verbatim} \end{kframe} \end{knitrout} @@ -23303,10 +23303,10 @@ \section{File Names and Operations}\label{sec:files:filenames} \begin{verbatim} ## [1] "abbrev.sty" ## [2] "anscombe.svg" -## [3] "Aphalo-CR-9781032518435-Learn-R-proofs-2024-01-26.pdf" -## [4] "Aphalo-CR-9781032518435-Learn-R.pdf" -## [5] "aphalo-Learn-R-2ed-crc-2023-06-14.pdf" -## [6] "aphalo-learn-R-2ed-draft-2022-02-01.pdf" +## [3] "Aphalo-CR-9781032518435-Learn-R-2024-02-17.pdf" +## [4] "Aphalo-CR-9781032518435-Learn-R-2024-03-05.pdf" +## [5] "Aphalo-CR-9781032518435-Learn-R-proofs-2024-01-26.pdf" +## [6] "Aphalo-CR-9781032518435-Learn-R.pdf" \end{verbatim} \begin{alltt} \hlkwd{head}\hlstd{(}\hlkwd{list.dirs}\hlstd{())} @@ -23350,9 +23350,9 @@ \section{File Names and Operations}\label{sec:files:filenames} \end{alltt} \begin{verbatim} ## size isdir mode mtime ctime -## xxx.txt 0 FALSE 666 2024-02-17 22:36:11 2024-02-17 22:36:11 +## xxx.txt 0 FALSE 666 2024-03-26 12:20:40 2024-03-26 12:20:40 ## atime exe -## xxx.txt 2024-02-17 22:36:11 no +## xxx.txt 2024-03-26 12:20:40 no \end{verbatim} \begin{alltt} \hlkwd{file.rename}\hlstd{(}\hlstr{"xxx.txt"}\hlstd{,} \hlstr{"zzz.txt"}\hlstd{)} @@ -24957,19 +24957,17 @@ \section{Data Acquisition from Physical Devices}\label{sec:data:acquisition} \hlstd{Meteo01.df} \hlkwb{<-} \hlkwd{fromJSON}\hlstd{(}\hlkwd{paste}\hlstd{(hub.url,} \hlstr{"byName/C1-Meteo/dataLogger.json"}\hlstd{,} \hlkwc{sep} \hlstd{=} \hlstr{""}\hlstd{),} \hlkwc{flatten} \hlstd{=} \hlnum{TRUE}\hlstd{)} +\end{alltt} + + +{\ttfamily\noindent\color{warningcolor}{\#\# Warning in open.connection(con, "{}rb"{}): URL 'http://localhost:4444/byName/C1-Meteo/dataLogger.json': status was 'Couldn't connect to server'}} + +{\ttfamily\noindent\bfseries\color{errorcolor}{\#\# Error in open.connection(con, "{}rb"{}): cannot open the connection to 'http://localhost:4444/byName/C1-Meteo/dataLogger.json'}}\begin{alltt} \hlkwd{str}\hlstd{(Meteo01.df,} \hlkwc{max.level} \hlstd{=} \hlnum{2}\hlstd{)} \end{alltt} -\begin{verbatim} -## 'data.frame': 3 obs. of 4 variables: -## $ id : chr "humidity" "pressure" "temperature" -## $ unit : chr "g/m3" "mbar" "'C" -## $ calib : chr "0," "0," "0," -## $ streams:List of 3 -## ..$ :'data.frame': 447 obs. of 5 variables: -## ..$ :'data.frame': 444 obs. of 5 variables: -## ..$ :'data.frame': 447 obs. of 5 variables: -\end{verbatim} -\end{kframe} + + +{\ttfamily\noindent\bfseries\color{errorcolor}{\#\# Error in eval(expr, envir, enclos): object 'Meteo01.df' not found}}\end{kframe} \end{knitrout} The minimum, mean, and maximum values for each logging interval need to be split from a single vector. We do this by indexing with a logical vector (recycled). The data returned are in long form, including measured values, quantity names, units, and the date and time when each value was acquired.