James-Thorson-NOAA / FishStatsUtils

Shared resources for spatio-temporal models
GNU General Public License v3.0
10 stars 16 forks source link

Error in make_covariates #35

Closed N-DucharmeBarth closed 4 years ago

N-DucharmeBarth commented 4 years ago

Hi Jim, I've come across the following error in the make_covariates function.

in rbind(deparse.level, ...) : numbers of columns of arguments do not match

The error is being thrown from the second rbind call in the function (line 70)

# Convert to dimensions requested
DF = rbind( DF_ip, DF_zp )

because DF_ip has 4 + n columns and DF_zp has 3+n columns, where n is the number of covariates specified in the covariate_data function argument.

The source of the error appears to stem from lines 39-40:

DF_ip = cbind( sample_data, covariate_data[rep(1,nrow(sample_data)),covariate_names] )
DF_ip[,covariate_names] = NA

which creates a 4+n columned data-frame with the names

Year, Lat, Lon, covariate_data[rep(1, nrow(sample_data)), covariate_names] plus whatever covariate_names is.

It looks like adding the following line

colnames(DF_ip) = c(names(sample_data),covariate_names)

in-between lines 39 & 40 solves the problem but this should be checked.

For reference I'm using R version 3.6.1, FishStatsUtils version 2.3.4 and VAST version 3.2.2.

James-Thorson-NOAA commented 4 years ago

Thanks Nicholas! After some back-and-forth, I have tested and pushed that proposed solution to the development branch of FishStatsUtils.

Nicholas -- could you run and do some sniff-tests for that push, and re-open the issue if you have anything to report?