Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in names(output) <- *vtmp* : 'names' attribute [1] must be the same length as the vector [0] #129

Open
vjjan91 opened this issue Jul 27, 2022 · 5 comments

Comments

@vjjan91
Copy link

vjjan91 commented Jul 27, 2022

Hi,

I am currently running into this error using the turnover function.

spTurnover <- turnover(df = turnover_dat, time.var = "year", species.var = "species", abundance.var = "abundance",
replicate.var = "site")

Error in names(output) <- *vtmp* :
'names' attribute [1] must be the same length as the vector [0]

Link to question below:
https://stackoverflow.com/questions/73142397/error-in-namesoutput-vtmp-names-attribute-1-must-be-the-same-leng

Any help would be greatly appreciated!

@pedrosenna
Copy link

pedrosenna commented Nov 6, 2022

Hi,

I am currently running into this error using the turnover function.

spTurnover <- turnover(df = turnover_dat, time.var = "year", species.var = "species", abundance.var = "abundance", replicate.var = "site")

Error in names(output) <- *vtmp* : 'names' attribute [1] must be the same length as the vector [0]

Link to question below: https://stackoverflow.com/questions/73142397/error-in-namesoutput-vtmp-names-attribute-1-must-be-the-same-leng

Any help would be greatly appreciated!

Did you find any solution? I am having the same issue.

Edit:

Seems to be a formating problem of the replicate column.

@mbjones
Copy link
Member

mbjones commented Nov 7, 2022

Hi @pedrosenna --

I am not seeing that error when I run the tests, and there is insufficient information in this ticket to replicate the problem. I suspect it is a problem with your input data not being structured as the function expects, but there is not enough info to tell. If you provide a reprex (reproducible example, see https://stackoverflow.com/a/5963610), it will likely surface the issue right away.

@crobbo27
Copy link

crobbo27 commented Apr 24, 2023

Hi pedrosenna and the community.

@pedrosenna did you manage to find a solution? I am experiencing the same problem. Strangely, I subset my dataset (into sediment and water samples) and the sediment samples work no problem, but the water sample subset returns this error....very strange!

R code for reference

`library(codyn)
library(readxl)
library(dplyr)
library(magrittr)
library(tidyr)

#load data
i6s_wide<-read_excel("16S_forcodyn.xlsx")
print(head(i6s_wide))

#Month Type SampleSite ASV_15 ASV_17 ASV_20 ASV_21 ASV_26 ASV_27
#MP1WJa Ja W MP1 164 345 67 0 154 102
#ASV_28 ASV_29 ASV_36 ASV_38 ASV_40 ASV_45 ASV_49 ASV_53 ASV_54
#MP1WJa 0 0 0 67 160 0 0 0 0
#ASV_57 ASV_59 ASV_63 ASV_71 ASV_77 ASV_80 ASV_81 ASV_85 ASV_86
#MP1WJa 0 0 0 85 0 0 13 0 0
#ASV_87 ASV_89 ASV_101 ASV_103 ASV_106 ASV_115 ASV_124 ASV_130
#MP1WJa 0 0 0 0 0 55 0 40
#ASV_139 ASV_152 ASV_154 ASV_155 ASV_174 ASV_178 ASV_182 ASV_191
#MP1WJa 0 0 0 89 95 0 0 0
#ASV_201 ASV_214 ASV_221 ASV_225 ASV_233 ASV_235 ASV_237 ASV_245
#MP1WJa 0 0 0 0 0 0 0 0
#ASV_249 ASV_253 ASV_256 ASV_260 ASV_265 ASV_269 ASV_271 ASV_273
#MP1WJa 0 0 0 0 0 0 17 0
#ASV_276 ASV_284 ASV_285 ASV_287 ASV_289 ASV_293 ASV_296 ASV_299
#MP1WJa 0 0 0 0 0 0 0 0
#ASV_311 ASV_323 ASV_327 ASV_330 ASV_353 ASV_356 ASV_364 ASV_371
#MP1WJa 0 0 0 43 0 0 0 0
#ASV_391 ASV_404 ASV_411 ASV_442 ASV_443 ASV_446 ASV_459 ASV_462
#MP1WJa 0 0 0 45 0 0 72 0
#ASV_463 ASV_466 ASV_490 ASV_506 ASV_508 ASV_527 ASV_530 ASV_548
#MP1WJa 0 0 0 0 0 48 0 0
#ASV_559 ASV_590 ASV_594 ASV_605 ASV_618 ASV_643 ASV_678 ASV_681
#MP1WJa 0 0 0 0 0 0 64 0
#ASV_682 ASV_688 ASV_704 ASV_711 ASV_720 ASV_727 ASV_740 ASV_743
#MP1WJa 0 0 0 0 0 0 0 0

i6s_wide <- i6s_wide %>%
tibble::column_to_rownames("Sample")

i6s_wide<-t(i6s_wide)
i6s_wide<-as.data.frame((i6s_wide))

i6s_long<-i6s_wide %>%
pivot_longer(
cols = starts_with("ASV_"),
names_to = "species",
names_prefix = "",
values_to = "abundance",
values_drop_na = TRUE
)

i6s_long$Month[i6s_long$Month=="Ja"]<-1
i6s_long$Month[i6s_long$Month=="M"]<-2
i6s_long$Month[i6s_long$Month=="Ju"]<-3
i6s_long$Month[i6s_long$Month=="S"]<-4
i6s_long$Month[i6s_long$Month=="N"]<-5

head(i6s_long)
#Month Type SampleSite species abundance
#
#1 1 W MP1 ASV_15 164
#2 1 W MP1 ASV_17 345
#3 1 W MP1 ASV_20 67
#4 1 W MP1 ASV_21 0
#5 1 W MP1 ASV_26 154
#6 1 W MP1 ASV_27 102

str(i6s_long)
i6s_long$Month<-as.numeric(i6s_long$Month)
i6s_long$abundance<-as.numeric(i6s_long$abundance)

str(i6s_long)

i6s_long_s<-subset(i6s_long, Type == "S")
head(i6s_long_s)
#A tibble: 6 × 5
#Month Type SampleSite species abundance

#1 1 S MP1 ASV_15 0
#2 1 S MP1 ASV_17 0
#3 1 S MP1 ASV_20 22
#4 1 S MP1 ASV_21 259
#5 1 S MP1 ASV_26 0
#6 1 S MP1 ASV_27 377

i6s_long_w<-subset(i6s_long, Type == "W")
head(i6s_long_w)
#A tibble: 6 × 5
#Month Type SampleSite species abundance
#
#1 1 W MP1 ASV_15 164
#2 1 W MP1 ASV_17 345
#3 1 W MP1 ASV_20 67
#4 1 W MP1 ASV_21 0
#5 1 W MP1 ASV_26 154
#6 1 W MP1 ASV_27 102

#Sediment
library(codyn)
sed_turnover <- turnover(df = i6s_long_s,
time.var = "Month",
species.var = "species",
abundance.var = "abundance",
replicate.var = "SampleSite")

#Water
wat_turnover <- turnover(df = i6s_long_w,
time.var = "Month",
species.var = "species",
abundance.var = "abundance",
replicate.var = "SampleSite")`

Error message: Error in names(output) <- *vtmp* :
'names' attribute [1] must be the same length as the vector [0]

@lagoodal
Copy link

lagoodal commented May 3, 2023

I had this problem and appear to have solved it. The error occurs when your replicate variable only has one timestamp/year. By this I mean that your replicate.var must have at least 2 years from which can calculate the turnover. It didn't work for me until I removed replicates (in my case unique sites) that only had one year within which there was an only one observation.

@mbjones
Copy link
Member

mbjones commented May 3, 2023

Glad you figured it out @lagoodal -- those types of issues are common and require tracking them down with the specific dataset you are using. I suspect the other issues in this thread are similar, but the details will vary. Providing a reprex is key to tracking these down, and the process of distilling the problem down to a reprex often reveals the issue directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants