Skip to main content
. 2022 Sep 1;18(9):e1010372. doi: 10.1371/journal.pcbi.1010372

Table 1. Examples of 3 styles of code, each changing an object (such as a data frame or a vector), using 2 verbs (functions that manipulate that object), and 2 arguments specifying those verbs (such as applying that function to only section X of the object).

If these look unintelligible to you, that’s okay! They are only meant to show that in R, there are different syntax strategies to complete the same tasks. If one looks more interpretable than the others, then great—you have found your coding style to begin!

Sequential Syntax Nested Syntax Piped Syntax
object_step1 <- verb1(object, argument1)

object_end <- verb2(object_step1, argument2)
object_end <-
    verb2(
        verb1(object,
            argument1
            ),
        argument2
        )
object_end <-

        object |>

          verb1(argument1) |>

          verb2(argument2)