What happens during an assessment in R?

I am wondering how the most basic thing, evaluation, works in R.

I came to R as a biologist and still was interested in everything related to the code, it is still a little mysterious.

I think I understand correctly:

But technically, what happens behind the curtain when we evaluate something in R, when we press enter after (or more) lines of code?

I found this in the R language definition with the main command:

When a user enters a command at a prompt (or when an expression is read from a file), the first thing that happens to him is that the command is converted by the parser to an internal representation. The evaluator performs the parsed expressions R and returns the value of the expression. All expressions matter. This is the core of the language.

But it is not interesting to me (especially the part in bold), and the subsection does not help me unravel it.

Do I have to open a fundamental book on computer science to understand this, or is there another way to understand, technically, what I do 8 hours a day?

+4
source share
1 answer

, , , " ". , R- R-, (, ) . pryr::call_tree(), , .

, :

> 1 + 2 - 3 * 4 / 5
[1] 0.6

, R. ? -, , "":

> parse(text = "1 + 2 - 3 * 4 / 5")
expression(1 + 2 - 3 * 4 / 5)

:

> library("pryr")
> call_tree(parse(text = "1 + 2 - 3 * 4 / 5"))
\- ()
  \- `-
  \- ()
    \- `+
    \-  1
    \-  2
  \- ()
    \- `/
    \- ()
      \- `*
      \-  3
      \-  4
    \-  5

, "*"(), "/"(), "+"(), "-"(). , :

> "-"("+"(1,2), "/"("*"(3,4), 5))
[1] 0.6
> call_tree(parse(text = '"-"("+"(1,2), "/"("*"(3,4), 5))'))
\- ()
  \- `-
  \- ()
    \- `+
    \-  1
    \-  2
  \- ()
    \- `/
    \- ()
      \- `*
      \-  3
      \-  4
    \-  5

:

> parse(text = "1; 2; 3")
expression(1, 2, 3)
> parse(text = "1\n2\n3")
expression(1, 2, 3)
> call_tree(parse(text = "1; 2; 3"))
\-  1

\-  2

\-  3

.

, R read-eval-print , , , , ), , :

> call_tree(parse(text = "2 + 'A'"))
\- ()
  \- `+
  \-  2
  \-  "A"

, :

> parse(text = "2 + +")
Error in parse(text = "2 + +") : <text>:2:0: unexpected end of input
1: 2 + +
   ^

, , , .

+4

All Articles