Running examples in 'qPRAentry-Ex.R' failed
The error most likely occurred in:

> ### Name: ntrade
> ### Title: Ntrade calculation
> ### Aliases: ntrade
> 
> ### ** Examples
> 
> ## Example with simulated trade data for Northern America
> library(dplyr)

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

> data("datatrade_NorthAm")
> # Total extra-import data: data contains imports from 5 third countries (column partner). 
> extra_total <- datatrade_NorthAm$extra_import
> # Extra-import data from countries where the pest is present (e.g., CNTR_1 and CNTR_2)
> CNTR_pest <- c("CNTR_1", "CNTR_2")
> extra_pest <- datatrade_NorthAm$extra_import %>% filter(partner%in%CNTR_pest)
> # Intra-trade data
> intra_trade  <- datatrade_NorthAm$intra_trade
> # Internal production data
> internal_production  <- datatrade_NorthAm$internal_production
> # Generate trade data (TradeData object)
> trade_NorthAm <- trade_data(extra_total = extra_total,
+                             extra_pest = extra_pest,
+                             intra_trade = intra_trade,
+                             internal_production = internal_production)
> # Calculation of the Ntrade for each time period
> ntrade_NorthAm <- ntrade(trade_data = trade_NorthAm)
> head(ntrade_NorthAm)
  country_IDs Ntrade_April-June Ntrade_January-March Ntrade_July-September
1          BM           670.412             8201.174              738.9461
2          CA          9503.115             1681.524             6186.5063
3          GL          9138.512             4034.844            14170.3812
4          PM          2076.277            12302.026             2618.0643
5          US          2306.934             5932.152             6174.8121
  Ntrade_October-December
1                3626.791
2                1386.109
3                6428.532
4                4263.005
5               10519.433
> # Ntrade summary for the time periods
> ntrade_NorthAm_summary <- ntrade(trade_data = trade_NorthAm,
+                                  summarise_result = c("mean", "sd", 
+                                                       "quantile(0.025)", 
+                                                       "median",
+                                                       "quantile(0.975)"))
> head(ntrade_NorthAm_summary)
  country_IDs     mean       sd   median    q0.025    q0.975
1          BM 3309.331 3540.324 2182.868  675.5521  7858.096
2          CA 4689.314 3888.968 3934.015 1408.2654  9254.369
3          GL 8443.067 4350.347 7783.522 4214.3705 13792.991
4          PM 5314.843 4750.018 3440.535 2116.9110 11699.099
5          US 6233.333 3360.625 6053.482 2578.8252 10193.586
> # Plot the median of Ntrade
> library(ggplot2)
> plot_countries(data = ntrade_NorthAm_summary,
+                iso_col = "country_IDs", 
+                values_col = "median") +
+   xlim(-180,-20) + ylim(0,90)
> 
> ## Example with simulated trade data for Europe 
> # Load data
> data("datatrade_EU")
> # Total extra-import data: the total import is identified as partner "Extra_Total"
> extra_total <- datatrade_EU$extra_import %>% filter(partner=="Extra_Total")
> # Extra-import data from countries where the pest is present
> extra_pest <- datatrade_EU$extra_import %>% filter(partner!="Extra_Total")
> # Intra-trade data
> intra_trade  <- datatrade_EU$intra_trade
> # Internal production data
> internal_production  <- datatrade_EU$internal_production
> # Generate trade data (TradeData object)
> trade_EU <- trade_data(extra_total = extra_total,
+                        extra_pest = extra_pest,
+                        intra_trade = intra_trade,
+                        internal_production = internal_production)
Note: For countries where Intra Export is greater than total available (Extra Total + Internal Production), Intra Export is considered proportional to the total available.
> # Ntrade mean and sd for the time periods
> ntrade_EU <- ntrade(trade_data = trade_EU,
+                     summarise_result = c("mean", "sd"))
> # Plot Ntrade mean
> plot_countries(data = ntrade_EU, 
+                iso_col="country_IDs", 
+                values_col="mean") +
+   xlim(-40,50) + ylim(25,70)