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

New 464 load module #526

Merged
merged 14 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(AgeComp)
export(BevertonHoltRecruitment)
export(CreateTMBModel)
export(DoubleLogisticSelectivity)
export(EWAAgrowth)
export(FIMSFrame)
export(FIMSFrameAge)
export(Fleet)
export(Index)
export(LogisticMaturity)
export(LogisticSelectivity)
export(Parameter)
export(Population)
export(TMBDlnormDistribution)
export(TMBDmultinomDistribution)
export(TMBDnormDistribution)
export(clear)
export(clear_logs)
export(create_fims_rcpp_interface)
export(get_fixed)
export(get_random)
export(m_agecomp)
export(m_index)
export(m_landings)
Expand Down
18 changes: 18 additions & 0 deletions R/FIMS-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,23 @@
#' @import methods
#' @importFrom ggplot2 .data
#' @importFrom usethis use_template ui_stop
#' @export CreateTMBModel
#' @export get_fixed
#' @export get_random
#' @export clear
#' @export clear_logs
#' @export Parameter
#' @export BevertonHoltRecruitment
#' @export Fleet
#' @export AgeComp
#' @export Index
#' @export Population
#' @export TMBDnormDistribution
#' @export LogisticMaturity
#' @export LogisticSelectivity
#' @export DoubleLogisticSelectivity
#' @export EWAAgrowth
#' @export TMBDlnormDistribution
#' @export TMBDmultinomDistribution
## usethis namespace: end
NULL
2 changes: 2 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Rcpp::loadModule(module = "fims", what = TRUE)

.onUnload <- function(libpath) {
library.dynam.unload("FIMS", libpath)
}
1 change: 0 additions & 1 deletion inst/include/interface/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// use isnan macro in math.h instead of TMB's isnan for fixing the r-cmd-check
// issue
#include <math.h>
//#define TMB_LIB_INIT R_init_FIMS
#include <TMB.hpp>

// define REPORT, ADREPORT, and SIMULATE
Expand Down
6 changes: 3 additions & 3 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @brief Rcpp interface for Data as an S4 object. To instantiate
* from R:
* fleet <- new(fims$Data)
* fleet <- new(Data)
*
*/
class DataInterfaceBase : public FIMSRcppInterfaceBase {
Expand Down Expand Up @@ -56,7 +56,7 @@ std::map<uint32_t, DataInterfaceBase*> DataInterfaceBase::live_objects;
/**
* @brief Rcpp interface for age comp data as an S4 object. To instantiate
* from R:
* acomp <- new(fims$AgeComp)
* acomp <- new(AgeComp)
*/
class AgeCompDataInterface : public DataInterfaceBase {
public:
Expand Down Expand Up @@ -123,7 +123,7 @@ class AgeCompDataInterface : public DataInterfaceBase {
/**
* @brief Rcpp interface for data as an S4 object. To instantiate
* from R:
* fleet <- new(fims$Index)
* fleet <- new(Index)
*/
class IndexDataInterface : public DataInterfaceBase {
public:
Expand Down
2 changes: 1 addition & 1 deletion inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std::map<uint32_t, FleetInterfaceBase*> FleetInterfaceBase::live_objects;
/**
* @brief Rcpp interface for Fleet as an S4 object. To instantiate
* from R:
* fleet <- new(fims$Fleet)
* fleet <- new(Fleet)
*
*/
class FleetInterface : public FleetInterfaceBase {
Expand Down
2 changes: 1 addition & 1 deletion inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::map<uint32_t, GrowthInterfaceBase*> GrowthInterfaceBase::live_objects;
/**
* @brief Rcpp interface for EWAAgrowth as an S4 object. To instantiate
* from R:
* ewaa <- new(fims$EWAAgrowth)
* ewaa <- new(EWAAgrowth)
*
*/
class EWAAGrowthInterface : public GrowthInterfaceBase {
Expand Down
2 changes: 1 addition & 1 deletion inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::map<uint32_t, MaturityInterfaceBase*> MaturityInterfaceBase::live_objects;

/**
* @brief Rcpp interface for logistic maturity as an S4 object. To
* instantiate from R: logistic_maturity <- new(fims$logistic_maturity)
* instantiate from R: logistic_maturity <- new(logistic_maturity)
*/
class LogisticMaturityInterface : public MaturityInterfaceBase {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ std::map<uint32_t, PopulationInterfaceBase*>
/**
* @brief Rcpp interface for a new Population. To instantiate
* from R:
* population <- new(fims$population)
* population <- new(population)
*/
class PopulationInterface : public PopulationInterfaceBase {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::map<uint32_t, RecruitmentInterfaceBase*>
/**
* @brief Rcpp interface for Beverton-Holt as an S4 object. To instantiate
* from R:
* beverton_holt <- new(fims$beverton_holt)
* beverton_holt <- new(beverton_holt)
*/
class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase {
public:
Expand Down
4 changes: 2 additions & 2 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::map<uint32_t, SelectivityInterfaceBase*>

/**
* @brief Rcpp interface for logistic selectivity as an S4 object. To
* instantiate from R: logistic_selectivity <- new(fims$logistic_selectivity)
* instantiate from R: logistic_selectivity <- new(logistic_selectivity)
*/
class LogisticSelectivityInterface : public SelectivityInterfaceBase {
public:
Expand Down Expand Up @@ -133,7 +133,7 @@ class LogisticSelectivityInterface : public SelectivityInterfaceBase {

/**
* @brief Rcpp interface for logistic selectivity as an S4 object. To
* instantiate from R: logistic_selectivity <- new(fims$logistic_selectivity)
* instantiate from R: logistic_selectivity <- new(logistic_selectivity)
*/
class DoubleLogisticSelectivityInterface : public SelectivityInterfaceBase {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::map<uint32_t,
/**
* @brief Rcpp interface for Dnorm as an S4 object. To instantiate
* from R:
* dnorm_ <- new(fims$TMBDnormDistribution)
* dnorm_ <- new(TMBDnormDistribution)
*
*/
class DnormDistributionsInterface : public DistributionsInterfaceBase {
Expand Down Expand Up @@ -128,7 +128,7 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase {
/**
* @brief Rcpp interface for Dlnorm as an S4 object. To instantiate
* from R:
* dlnorm_ <- new(fims$TMBDlnormDistribution)
* dlnorm_ <- new(TMBDlnormDistribution)
*
*/
class DlnormDistributionsInterface : public DistributionsInterfaceBase {
Expand Down Expand Up @@ -200,7 +200,7 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase {
/**
* @brief Rcpp interface for Dmultinom as an S4 object. To instantiate
* from R:
* dmultinom_ <- new(fims$TMBDmultinomDistribution)
* dmultinom_ <- new(TMBDmultinomDistribution)
*
*/
// template <typename Type>
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/test-data-object.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,30 @@ fleet_names_index <- dplyr::filter(
nindex <- length(fleet_names_index)

test_that("Can add index data to model", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")

indexdat <- vector(mode = "list", length = nindex)
names(indexdat) <- fleet_names_index

for (index_i in 1:nindex) {
index <- fims$Index
index <- Index
indexdat[[fleet_names_index[index_i]]] <- new(index, nyears)
expect_silent(indexdat[[fleet_names_index[index_i]]] <-
m_index(age_frame, fleet_names_index[index_i]))
}

fims$clear()
clear()
})

test_that("Can add agecomp data to model", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")

agecompdat <- vector(mode = "list", length = nagecomp)
names(agecompdat) <- fleet_names_agecomp

for (fleet_f in 1:nagecomp) {
agecompdat[[fleet_names_agecomp[fleet_f]]] <- new(fims$AgeComp, nyears, nages)
agecompdat[[fleet_names_agecomp[fleet_f]]] <- new(AgeComp, nyears, nages)
expect_silent(agecompdat[[fleet_names_agecomp[fleet_f]]]$age_comp_data <-
m_agecomp(age_frame, fleet_names_agecomp[fleet_f]))
}

fims$clear()
clear()
})
7 changes: 3 additions & 4 deletions tests/testthat/test-ewaa.r
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
data(package = "FIMS")

test_that("ewaa data can be added to model", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")
ewaa_growth <- new(fims$EWAAgrowth)
ewaa_growth <- new(EWAAgrowth)
age_frame <- FIMSFrameAge(data_mile1)
ewaa_growth$ages <- m_ages(age_frame)
ewaa_growth$weights <- m_weightatage(age_frame)
expect_equal(ewaa_growth$evaluate(1), 0.00053065552)

ewaa_growth2 <- new(fims$EWAAgrowth)
ewaa_growth2 <- new(EWAAgrowth)
ewaa_growth2$ages <- c(ewaa_growth$ages, 12)
ewaa_growth2$weights <- m_weightatage(age_frame)
expect_error(
Expand All @@ -17,5 +16,5 @@ test_that("ewaa data can be added to model", {
ignore.case = FALSE
)

fims$clear()
clear()
})
11 changes: 5 additions & 6 deletions tests/testthat/test-fims-rcpp.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
test_that("Rcpp interface works for modules", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")

expect_no_error(parameter <- new(fims$Parameter, .1))
expect_no_error(beverton_holt <- new(fims$BevertonHoltRecruitment))
expect_no_error(logistic_selectivity <- new(fims$LogisticSelectivity))
expect_no_error(ewaa_growth <- new(fims$EWAAgrowth))
expect_no_error(parameter <- new(Parameter, .1))
expect_no_error(beverton_holt <- new(BevertonHoltRecruitment))
expect_no_error(logistic_selectivity <- new(LogisticSelectivity))
expect_no_error(ewaa_growth <- new(EWAAgrowth))
logistic_selectivity$slope$value <- .7
logistic_selectivity$inflection_point$value <- 5.0

Expand All @@ -18,5 +17,5 @@ test_that("Rcpp interface works for modules", {
expect_equal(ewaa_growth$get_id(), 1)
expect_equal(beverton_holt$get_id(), 1)

fims$clear()
clear()
})
31 changes: 13 additions & 18 deletions tests/testthat/test-fleet-interface.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
test_that("Fleet: selectivity IDs can be added to the
fleet module", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")

# Create selectivity for fleet 1
selectivity_fleet1 <- new(fims$LogisticSelectivity)
selectivity_fleet1 <- new(LogisticSelectivity)
expect_equal((selectivity_fleet1$get_id()), 1)

# Create selectivity for fleet 2
selectivity_fleet2 <- new(fims$LogisticSelectivity)
selectivity_fleet2 <- new(LogisticSelectivity)
expect_equal((selectivity_fleet2$get_id()), 2)

# Add selectivity to fleet
fleet1 <- new(fims$Fleet)
fleet2 <- new(fims$Fleet)
fleet1 <- new(Fleet)
fleet2 <- new(Fleet)

# Expect code produces no output, error, message, or warnings
expect_silent(fleet1$SetSelectivity(selectivity_fleet1$get_id()))
Expand All @@ -21,42 +20,38 @@ fleet module", {
# Expect code produces error when ID of selectivity is a character string
expect_error(fleet1$SetSelectivity("id"))

fims$clear()
clear()
})


test_that("Fleet: SetAgeCompLikelihood works", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")
fleet <- new(fims$Fleet)
fleet <- new(Fleet)

expect_silent(fleet$SetAgeCompLikelihood(1))

fims$clear()
clear()
})

test_that("Fleet: SetIndexLikelihood works", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")
fleet <- new(fims$Fleet)
fleet <- new(Fleet)

expect_silent(fleet$SetIndexLikelihood(1))

fims$clear()
clear()
})

test_that("Fleet: SetObservedAgeCompData works", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")
fleet <- new(fims$Fleet)
fleet <- new(Fleet)

expect_silent(fleet$SetObservedAgeCompData(1))

fims$clear()
clear()
})

test_that("Fleet: SetObservedIndexData works", {
fims <- Rcpp::Module("fims", PACKAGE = "FIMS")
fleet <- new(fims$Fleet)
fleet <- new(Fleet)

expect_silent(fleet$SetObservedIndexData(1))

fims$clear()
clear()
})
Loading
Loading