Creating an object inside the names <- () gives an error. How to explain?

it

x <- list(12, 13)
names(y <- x) <- c("a", "b")

gives an error:

Error in names(y <- x) <- c("a", "b") : object 'y' not found

Can someone explain why?

According to R, scoring rules y <- xmust be scored within the parent <-. Therefore, y must be created in a global environment.

Thank.

[update] If the object is yalready present in the global environment, then the error:

Error in names(y <- x) <- c("a", "b") : could not find function "<-<-"

[update2] Here is another design I came across today.

(X <- matrix(0, nrow = 10, ncol = 10))[1:3] <- 3:5
Error during wrapup: object 'X' not found
+3
source share
2 answers

, <- LHS, "<-" , . . :

x <- a <- 1
`f<-` <- function(x, a, value) x
f(x, a <- 2) <- 2
f(x <- 2, a) <- 2
# Error in f(x <- 2, a) <- 2 : could not find function "<-<-"

, , setNames.

+3

, , . , . -, y . , y.

2 , , , .

+1

Source: https://habr.com/ru/post/1769763/


All Articles