Tazinho / Advanced-R-Solutions

Set of solutions for the Advanced R programming book
https://advanced-r-solutions.rbind.io/
290 stars 118 forks source link

Differing answers in Section 6 Question 5 b and c #292

Closed jamesmbaazam closed 9 months ago

jamesmbaazam commented 10 months ago

Thank you for this solution manual. It has been useful to me.

I would like to point out a difference in answers in Section 6 Questions 5b and c.

library(purrr)
# Question 5(b)
objs <- mget(ls("package:base", all = TRUE), inherits = TRUE)
funs <- Filter(is.function, objs)
n_args <- funs %>%
  map(formals) %>%
  map_int(length)
sum(n_args == 0)
#> [1] 253

# Question 5(c)
n_args2 <- funs %>% 
  discard(is.primitive) %>% 
  map(formals) %>%
  map_int(length)

sum(n_args2 == 0)
#> [1] 48
Created on 2024-02-05 with [reprex v2.1.0](https://reprex.tidyverse.org/)

I think it's probably a difference in the R versions. I use R4.3.2.

Tazinho commented 9 months ago

Hi, yes this is due to different R Versions. The print version was rendered with 4.0.3 and the html Version is also not the most recent.