Open markpayneatwork opened 4 years ago
Thanks Mark! Yes a documentation problem. It returns a list of data.frames - one for each stock key provided.
so for ecxampe:
assessmentKeys <- findAssessmentKey("cod", year = 2019, full = TRUE)
assessmentKeys <- unique(assessmentKeys) # having to do this indicates a bug though...
sumtab <- getSummaryTable(assessmentKeys$AssessmentKey)
str(sumtab, 1)
# List of 16
# $ :'data.frame': 44 obs. of 24 variables:
# $ :'data.frame': 67 obs. of 24 variables:
# $ :'data.frame': 47 obs. of 24 variables:
# $ :'data.frame': 74 obs. of 24 variables:
# $ :'data.frame': 35 obs. of 24 variables:
# $ :'data.frame': 23 obs. of 24 variables:
# $ :'data.frame': 35 obs. of 24 variables:
# $ :'data.frame': 74 obs. of 24 variables:
# $ :'data.frame': 57 obs. of 24 variables:
# $ :'data.frame': 57 obs. of 24 variables:
# $ :'data.frame': 67 obs. of 24 variables:
# $ :'data.frame': 61 obs. of 24 variables:
# $ :'data.frame': 55 obs. of 24 variables:
# $ :'data.frame': 39 obs. of 24 variables:
# $ :'data.frame': 51 obs. of 24 variables:
# $ :'data.frame': 49 obs. of 24 variables:
head(
sumtab[[
which(
assessmentKeys$StockKeyLabel == "cod.21.1" &
assessmentKeys$Purpose == "Advice"
)
]]
)
# Year recruitment high_recruitment low_recruitment low_SSB SSB high_SSB catches landings
# 1 1976 14515 34209 6159 5177 7598 11151 NA 5174
# 2 1977 20885 46241 9433 10904 17996 29702 NA 13999
# 3 1978 44659 104978 18999 17970 32800 59868 NA 19679
# 4 1979 15111 35785 6381 27186 48796 87587 NA 35590
# 5 1980 43223 106786 17495 22570 37858 63502 NA 38571
# 6 1981 16230 35795 7359 17200 25104 36639 NA 39703
# discards low_F F high_F StockPublishNote Purpose Fage fishstock recruitment_age
# 1 NA 0.394 0.591 0.888 Stock published Advice 4-8 cod.21.1 1
# 2 NA 0.420 0.598 0.851 Stock published Advice 4-8 cod.21.1 1
# 3 NA 0.392 0.537 0.736 Stock published Advice 4-8 cod.21.1 1
# 4 NA 0.436 0.579 0.769 Stock published Advice 4-8 cod.21.1 1
# 5 NA 0.501 0.655 0.855 Stock published Advice 4-8 cod.21.1 1
# 6 NA 0.577 0.755 0.990 Stock published Advice 4-8 cod.21.1 1
# AssessmentYear units stockSizeDescription stockSizeUnits fishingPressureDescription
# 1 2019 tonnes SSB tonnes F
# 2 2019 tonnes SSB tonnes F
# 3 2019 tonnes SSB tonnes F
# 4 2019 tonnes SSB tonnes F
# 5 2019 tonnes SSB tonnes F
# 6 2019 tonnes SSB tonnes F
# fishingPressureUnits
# 1 Year-1
# 2 Year-1
# 3 Year-1
# 4 Year-1
# 5 Year-1
# 6 Year-1
Will update docs - thanks for this!
Ok great.
As a design comment, would it not be cleaner to have it returned as a dataframe with the first column being “stock” or similar? There seems to be a move in the R community (at least in the tidyverse anyway) away from lists towards tibbles / dataframes wherever possible?
I think so - we can add an argument, simplifyToDataFrame
or similar, which will return a data.frame. with the defaut as FALSE
to maintain back compatability.
Will implement and close issue when I push the changes.
According to the documentation,
getSummaryTable()
should return a dataframe. However, it returns a list:Unsure if this is a bug in the documentation or the code...