Error in (function (object, ...) : missing values in `weights'

Hi there,

I'm using 4 survey cycles (2006 - 2013) of the Nhanes data (N=40,617) and am interested in pregnant women (n= 247) who are black and Hispanic. I am trying to correct for survey design, non-response, etc., per Nhanes by applying weights as in the code below. However, I keep getting the above error message that I'm not sure how to correct.

Demo_Metals <- left_join(DEMO_BMX, Metals_0613, by="SEQN")%>%
mutate(. ,
# Generating 8-year subsample weights (Dividing weights by 4 because we are appending 4 survey cycles). Using the subsample weights (WTSA2YR), per the analytic notes on the metals documentation
WTSA8YR = WTSA2YR/4,
# Defining indicator for analysis pop
inAnalysis= (RIDEXPRG=1 & RIDRETH1 != c(3, 5) & !is.na(WTSA2YR)))%>%

#' ## Defining survey design for overall dataset
NHANES_all <- svydesign(data=Demo_Metals, id=~SDMVPSU, strata=~SDMVSTRA, weights=~WTSA8YR, nest=TRUE)

#Creating a survey design object for the subset of interest - pregnant, black, and Hispanic women.

# Subsetting the original survey design object to keep the design information about the number of cluster, and strata

NHANES <- subset(NHANES_all, inAnalysis)

This is a sample of the data frame

dput(head(Demo_Metals, 10))
structure(list(SEQN = c(41475, 41476, 41477, 41478, 41479, 41480,
41481, 41482, 41483, 41484), DMDEDUC2 = c(3, NA, 3, NA, 1, NA,
3, 2, 4, NA), INDFMIN2 = c(6, 15, 5, 3, 8, 4, 6, 15, 5, 3), RIDRETH1 = c(5,
5, 3, 3, 1, 1, 4, 1, 4, 3), RIDAGEYR = c(62, 6, 71, 1, 52, 6,
21, 64, 66, 0), RIDEXPRG = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_),
SDMVSTRA = c(60, 70, 67, 59, 70, 69, 68, 65, 66, 59), SDMVPSU = c(1,
1, 1, 2, 1, 2, 2, 2, 2, 2), WTMEC2YR = c(60045.772497, 35353.21044,
10074.150074, 14560.472652, 9234.055759, 7297.067503, 24655.376656,
11602.178638, 7920.812275, 9259.270099), BMXBMI = c(58.04,
15.18, 30.05, NA, 27.56, 17.93, 23.34, 33.64, 44.06, NA),
LBXBCD = c(0.2, 0.14, 0.14, 0.14, 0.14, NA, NA, 0.42, 0.57,
NA), LBDBCDSI = c(1.78, 1.25, 1.25, 1.25, 1.25, NA, NA, 3.74,
5.07, NA), LBXBPB = c(1.1, 1.94, 0.9, 2.28, 1.7, NA, NA,
0.99, 2.17, NA), LBDBPBSI = c(0.053, 0.094, 0.043, 0.11,
0.082, NA, NA, 0.048, 0.105, NA), LBXTHG = c(0.2, 2.6, 1.31,
0.2, 1.22, NA, NA, 0.64, 0.65, NA), LBDTHGSI = c(1, 13, 6.5,
1, 6.1, NA, NA, 3.2, 3.2, NA), LBDTHGLC = c(1, 0, 0, 1, 0,
NA, NA, 0, 0, NA), Matrix.x = c("Blood", "Blood", "Blood",
"Blood", "Blood", "Blood", "Blood", "Blood", "Blood", NA),
WTSA2YR.x = c(NA, NA, 28753.7444494525, NA, NA, 23899.3095881372,
75774.2128638516, 34222.0864226224, NA, NA), URXUCR.x = c(NA,
NA, 135, NA, NA, 33, 366, 130, NA, NA), URXUAS = c(NA, NA,
98.88, NA, NA, 6.57, 9.49, 6.17, NA, NA), URDUASLC = c(NA,
NA, 0, NA, NA, 0, 0, 0, NA, NA), URXUAS3 = c(NA, NA, 0.85,
NA, NA, 0.85, 0.85, 0.85, NA, NA), URDUA3LC = c(NA, NA, 1,
NA, NA, 1, 1, 1, NA, NA), URXUAS5 = c(NA, NA, 0.71, NA, NA,
0.71, 0.71, 0.71, NA, NA), URDUA5LC = c(NA, NA, 1, NA, NA,
1, 1, 1, NA, NA), URXUAB = c(NA, NA, 72.2, NA, NA, 0.61,
2.19, 0.28, NA, NA), URDUABLC = c(NA, NA, 0, NA, NA, 0, 0,
1, NA, NA), URXUAC = c(NA, NA, 0.42, NA, NA, 0.42, 0.42,
0.42, NA, NA), URDUACLC = c(NA, NA, 1, NA, NA, 1, 1, 1, NA,
NA), URXUDMA = c(NA, NA, 5, NA, NA, 4.56, 4.48, 3.53, NA,
NA), URDUDALC = c(NA, NA, 0, NA, NA, 0, 0, 0, NA, NA), URXUMMA = c(NA,
NA, 0.64, NA, NA, 0.64, 1.09, 0.64, NA, NA), URDUMMAL = c(NA,
NA, 1, NA, NA, 1, 0, 1, NA, NA), URXUTM = c(NA, NA, 0.71,
NA, NA, 0.71, 0.71, 0.71, NA, NA), URDUTMLC = c(NA, NA, 1,
NA, NA, 1, 1, 1, NA, NA), Matrix.y = c(NA, NA, "Urine", NA,
NA, "Urine", "Urine", "Urine", NA, NA), WTSA2YR.y = c(NA,
NA, 28753.7444494525, NA, NA, 23899.3095881372, 75774.2128638516,
34222.0864226224, NA, NA), URXUCR.y = c(NA, NA, 135, NA,
NA, 33, 366, 130, NA, NA), URXUBA = c(NA, NA, 4.64, NA, NA,
0.52, 1.54, 2.19, NA, NA), URDUBALC = c(NA, NA, 0, NA, NA,
0, 0, 0, NA, NA), URXUBE = c(NA, NA, 0.051, NA, NA, 0.051,
0.051, 0.051, NA, NA), URDUBELC = c(NA, NA, 1, NA, NA, 1,
1, 1, NA, NA), URXUCD = c(NA, NA, 0.218, NA, NA, 0.03, 0.24,
1.03, NA, NA), URDUCDLC = c(NA, NA, 0, NA, NA, 1, 0, 0, NA,
NA), URXUCO = c(NA, NA, 0.639, NA, NA, 0.128, 0.561, 0.373,
NA, NA), URDUCOLC = c(NA, NA, 0, NA, NA, 0, 0, 0, NA, NA),
URXUCS = c(NA, NA, 6.74, NA, NA, 6.34, 7.6, 4.81, NA, NA),
URDUCSLC = c(NA, NA, 0, NA, NA, 0, 0, 0, NA, NA), URXUMO = c(NA,
NA, 52.3, NA, NA, 49.2, 74.6, 161, NA, NA), URDUMOLC = c(NA,
NA, 0, NA, NA, 0, 0, 0, NA, NA), URXUPB = c(NA, NA, 0.53,
NA, NA, 0.37, 0.73, 0.56, NA, NA), URDUPBLC = c(NA, NA, 0,
NA, NA, 0, 0, 0, NA, NA), URXUPT = c(NA, NA, 0.006, NA, NA,
0.006, 0.006, 0.006, NA, NA), URDUPTLC = c(NA, NA, 1, NA,
NA, 1, 1, 1, NA, NA), URXUSB = c(NA, NA, 0.066, NA, NA, 0.059,
0.115, 0.056, NA, NA), URDUSBLC = c(NA, NA, 0, NA, NA, 0,
0, 0, NA, NA), URXUTL = c(NA, NA, 0.235, NA, NA, 0.115, 0.179,
0.186, NA, NA), URDUTLLC = c(NA, NA, 0, NA, NA, 0, 0, 0,
NA, NA), URXUTU = c(NA, NA, 0.104, NA, NA, 0.107, 0.506,
0.021, NA, NA), URDUTULC = c(NA, NA, 0, NA, NA, 0, 0, 0,
NA, NA), URXUUR = c(NA, NA, 0.0137, NA, NA, 0.0055, 0.0126,
0.01, NA, NA), URDUURLC = c(NA, NA, 0, NA, NA, 0, 0, 0, NA,
NA), Matrix = c(NA, NA, "Urine", NA, NA, "Urine", "Urine",
"Urine", NA, NA), LBDBCDLC = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), LBDBPBLC = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), LBXBSE = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), LBDBSESI = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), LBDBSELC = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), LBXBMN = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), LBDBMNSI = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), LBDBMNLC = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), URXUMN = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), URDUMNLC = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), URXUSN = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), URDUSNLC = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), URXUSR = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), URDUSRLC = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), Matrix.x.x = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_), WTSA2YR = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), URXUCR = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), LBXSCU = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), LBDSCUSI = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), LBXSSE = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), LBDSSESI = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), LBXSZN = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), LBDSZNSI = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Matrix.y.y = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_), WTSH2YR = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_)), row.names = c(NA, 10L), class = "data.frame")

I'm new to R so I may be missing the obvious. Happy to provide any further information as needed so that I can go past this error message. Thanks.

What function in which library is producing the error?

I'm not sure, but I'm using the following:
library(dplyr)
library(survey)
library(extraoperators)

The function will be the one that was called before the error

... # your preceding script
some_function(...) # calling function and it's arguments
... # one or more lines
ERROR message

I ran the whole code as posted and obtained the error just as posted and so I'm not sure. If I run the code to the level of the svdesign function I get the error "Error in eval(predvars, data, env) : object 'WTSA8YR' not found"

See the FAQ: How to do a minimal reproducible example reprex for beginners. That error message might arise from svydesign(), probably not from subset(), but it's impossible to tell. There's not even a complete error message error provided. Up to the user to provide what's needed to make it possible for the community here (we're almost all unpaid volunteers) to help the user.