Login
You're viewing the mastodonapp.uk public feed.
  • RadicalEcologistRadicalEcologist@todon.eu
    Jun 4, 2026, 2:43 PM

    @adam_wysokinski
    I think of subsetting in R as the creation of a new object with NA as the default value that then gets replaced until the end of the source is found or the new object is full. R will happily let you shoot your own foot. To avoid this you have to plan ahead and decide what should error and what should be kept dynamic. There are many ways to do this. Here is an illustrative example.
    ```R
    # no error, dynamic size allowed
    x <- c(1,2,3)
    x1 <- x[1:length(x)]
    print(x1)

    # error, dynamic size fails
    x2 <- vector(length=4)
    if(length(x2)==length(na.omit(x[1:4]))){
    x2 <- x[1:4]
    print(x2)
    }else{
    print("error handler here")
    }
    ```
    You can also use [[]] which will show the expected error.

    R is amazing at data processing, visualizing, and prototyping. However, critical code is best moved to other languages. Rcpp makes c++ extremely easy to integrate. That gives you strong typing, throws errors you probably expect, and massive performance improvements.

    💬 0🔄 1⭐ 0