kenhanscombe / ukbtools

An R package to manipulate and explore UK Biobank data
https://kenhanscombe.github.io/ukbtools/
96 stars 26 forks source link

ukb_context doesn't work with new variables in dataset #23

Closed ntraut closed 4 years ago

ntraut commented 4 years ago

Hello, I get this error when I try to follow the example of the vignette:

subgroup_of_interest <- (my_ukb_data$body_mass_index_bmi_f21001_0_0 >= 25) 
ukb_context(my_ukb_data, subset.var = subgroup_of_interest)
Error: More than one expression parsed
Call `rlang::last_error()` to see a backtrace

I identified that the problem comes for the variable sex.var in the function ukb_context. The pattern sex.var = "^sex.*0_0" matches several variables:

Browse[3]> sex.var
[1] "sex_f31_0_0"                                                                       
[2] "sexually_molested_as_a_child_f20490_0_0"                                           
[3] "sexual_interference_by_partner_or_expartner_without_consent_as_an_adult_f20524_0_0"
[4] "sex_chromosome_aneuploidy_f22019_0_0"                                              
[5] "sex_inference_x_probeintensity_f22022_0_0"                                         
[6] "sex_inference_y_probeintensity_f22023_0_0"                                         
[7] "sex_of_baby_f41226_0_0"
kenhanscombe commented 4 years ago

Thanks for picking that up - I'll change the regex.

You should be able to set the parameter explicitly,sex.var = "sex_f31_0_0".

Let me know if that works for you.

ntraut commented 4 years ago

Working for me, thanks.

kenhanscombe commented 4 years ago

Hard-coded demographic variable default arguments:

sex.var = "sex_f31_0_0",
age.var = "age_when_attended_assessment_centre_f21003_0_0"
socioeconomic.var = "townsend_deprivation_index_at_recruitment_f189_0_0"
ethnicity.var = "ethnic_background_f21000_0_0"
employment.var = "current_employment_status_f6142_0_0"
centre.var = "uk_biobank_assessment_centre_f54_0_0"