rparentheses

Why do people use parentheses surrounding functions and assignments in R?


Lately I've seen several of these instances:

(NCORES <- nb_cores())

Or:

(ldsc <- with(df_beta, snp_ldsc(ld, ld_size = nrow(map_ldref),
                                chi2 = (beta / beta_se)^2,
                                sample_size = n_eff,
                                ncores = NCORES)))

Why do people use outer parenthesis?


Solution

  • Wrapping R code in parenthesis like this (NCORES <- nb_cores()) ensures that the output of the function nb_cores() is both assigned to the variable NCORES and also printed to the R console.