From 771b5df569ae3099dcad401aa6f377f41282046a Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Feb 2019 15:53:05 -0500 Subject: [PATCH 1/3] Tidy dependencies --- .travis.yml | 1 - DESCRIPTION | 6 +- ru.sh | 4 + vignettes/siteonly/pandoc53547b2d4760.html | 769 --------------------- 4 files changed, 7 insertions(+), 773 deletions(-) create mode 100644 ru.sh delete mode 100644 vignettes/siteonly/pandoc53547b2d4760.html diff --git a/.travis.yml b/.travis.yml index 8819ed9..8bc7bd1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ matrix: before_deploy: - Rscript -e 'remotes::install_cran("pkgdown")' - Rscript -e 'remotes::install_github("maurolepore/pkgdoc")' - - Rscript -e 'install.packages("DT")' deploy: provider: script script: Rscript -e 'pkgdown::deploy_site_github()' diff --git a/DESCRIPTION b/DESCRIPTION index 397b189..b49eff5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -120,9 +120,9 @@ Suggests: knitr (>= 1.21), rmarkdown (>= 1.11), spelling (>= 2.0), - testthat (>= 2.0.1) -Additional_repositories: https://cran.rstudio.com/, - https://forestgeo.github.io/drat/ + testthat (>= 2.0.1), + kableExtra +Additional_repositories: https://forestgeo.github.io/drat/ Encoding: UTF-8 Language: en-US LazyData: true diff --git a/ru.sh b/ru.sh new file mode 100644 index 0000000..b26be8c --- /dev/null +++ b/ru.sh @@ -0,0 +1,4 @@ +git checkout master +git fetch upstream +git reset --hard upstream/master +git remote prune origin diff --git a/vignettes/siteonly/pandoc53547b2d4760.html b/vignettes/siteonly/pandoc53547b2d4760.html deleted file mode 100644 index b6dfc4f..0000000 --- a/vignettes/siteonly/pandoc53547b2d4760.html +++ /dev/null @@ -1,769 +0,0 @@ - - - - - - - - - - - - - - -Get started - - - - - - - - - - - - - - - - - - -

Get started

- - - -

This article shows some of the key features of fgeo applied to an exploratory data analysis. For a deeper and general approach to exploratory data analysis, see this book section. A version adapted for ForestGEO is available here.

-
-

Packages

-

In every new R session you need to “open” fgeo with library().

- -

You may suppress the startup message with suppressPackageStartupMessages() or add options("fgeo.quiet" = TRUE) to .Rprofile (see usethis::edit_r_profile()).

-
-
-

Data

-

You may use you own data but fgeo comes with some example datasets.

- -

We will use a dataset of stems censused in one hectare from the forest plot in Luquillo, Puerto Rico (https://forestgeo.si.edu/sites/north-america/luquillo).

- -

This dataset comes with multiple censuses but we’ll work with the latest one.

- -

For a description of the columns, see ?data_dictionary.

-
data_dictionary <- download_data("data_dictionary")
-str(data_dictionary)
-#> Classes 'tbl_df', 'tbl' and 'data.frame':    242 obs. of  3 variables:
-#>  $ table      : chr  "Census" "Census" "Census" "Census" ...
-#>  $ column     : chr  "CensusID" "PlotID" "PlotCensusNumber" "StartDate" ...
-#>  $ description: chr  "Primary key, an integer  automatically generated to uniquely identify a census." "Foreign Key to Site table." "Integer census number for an individual plot, 1=first census, 2=second census, etc. If there are more than one "| __truncated__ "Date on which the first measurement of the census was taken." ...
-
-cols <- names(stem)
-filter(data_dictionary, column %in% cols)
-#> # A tibble: 20 x 3
-#>    table           column   description                                    
-#>    <chr>           <chr>    <chr>                                          
-#>  1 Census          CensusID Primary key, an integer  automatically generat~
-#>  2 CensusQuadrat   CensusID Foreign Key to Census table.                   
-#>  3 DataCollection  CensusID Foreign Key to Census table.                   
-#>  4 DBH             CensusID Foreign Key to Census table.                   
-#>  5 DBH             ExactDa~ Date on which the measurement was taken.       
-#>  6 DBHAttributes   CensusID Foreign Key to Census table.                   
-#>  7 Measurement     Measure~ Primary key, an integer  automatically generat~
-#>  8 Measurement     CensusID Foreign Key to Census table.                   
-#>  9 Measurement     ExactDa~ "Date on which measurement has been done  (for~
-#> 10 MeasurementAtt~ Measure~ Foreign Key to Measurement table.              
-#> 11 MeasurementAtt~ CensusID Foreign Key to Census table.                   
-#> 12 RemeasAttribs   CensusID Foreign Key to Census table.                   
-#> 13 Remeasurement   CensusID Foreign Key to  Census table.                  
-#> 14 Remeasurement   ExactDa~ "Date of remeasurement.  (format is yyyy-mm-dd~
-#> 15 SpeciesInvento~ CensusID Foreign Key to  Census table.                  
-#> 16 Stem            StemTag  The stem tag used in the field to identify the~
-#> 17 TreeAttributes  CensusID Foreign Key to  Census table.                  
-#> 18 ViewFullTable   StemTag  The stem tag used in the field to identify the~
-#> 19 ViewFullTable   CensusID Foreign Key to  Census table.                  
-#> 20 ViewFullTable   ExactDa~ Date on which the measurement was taken (forma~
-
-
-

Demography

- -

With to_df() we convert the result of any demography function to a tibble – a convenient dataframe.

- -

We can aggregate results by any number of variables:

- - - - -

To separate the multiple groups we can use tidyr::separate().

- -

The same works for mortality and growth.

-
to_df(mortality_ctfs(census5, census6, split1 = sp_quadrat))
-#> Detected dbh ranges:
-#>   * `census1` = 10-955.
-#>   * `census2` = 10.2-992.
-#> Using dbh `mindbh = 0` and above.
-#> # A tibble: 26,207 x 10
-#>    groups          N     D  rate  lower   upper  time date1 date2 dbhmean
-#>    <chr>       <dbl> <dbl> <dbl>  <dbl>   <dbl> <dbl> <dbl> <dbl>   <dbl>
-#>  1 PREMON.1001     1     0     0 0        0.399  4.62 18806 20495   136  
-#>  2 DACEXC.1002     1     0     0 0        0.399  4.63 18805 20495   419  
-#>  3 DACEXC.1005     1     0     0 0        0.404  4.56 18849 20515    58  
-#>  4 TRIPAL.1005     1     1   Inf 0.0377 Inf      4.56 18849 20515    42.5
-#>  5 MANBID.1006     1     0     0 0        0.404  4.56 18849 20515    30.6
-#>  6 EUGSTA.1007     1     0     0 0        0.410  4.50 18891 20534    55  
-#>  7 MANBID.1007     1     0     0 0        0.410  4.50 18892 20535    15  
-#>  8 MATDOM.1007     1     0     0 0        0.410  4.50 18891 20535   240  
-#>  9 MICPRA.1007     1     1   Inf 0.0383 Inf      4.50 18891 20534    12.2
-#> 10 SLOBER.1007     1     1   Inf 0.0382 Inf      4.50 18890 20534   101  
-#> # ... with 26,197 more rows
-
-to_df(growth_ctfs(census5, census6, split1 = sp_quadrat))
-#> Detected dbh ranges:
-#>   * `census1` = 10-955.
-#>   * `census2` = 10.2-992.
-#> Using dbh `mindbh = 0` and above.
-#> # A tibble: 26,207 x 8
-#>    groups          rate     N  clim dbhmean  time date1 date2
-#>    <chr>          <dbl> <dbl> <dbl>   <dbl> <dbl> <dbl> <dbl>
-#>  1 PREMON.1001  -0.216      1    NA   136    4.62 18806 20495
-#>  2 DACEXC.1002   0.864      1    NA   419    4.63 18805 20495
-#>  3 DACEXC.1005   0.438      1    NA    58    4.56 18849 20515
-#>  4 TRIPAL.1005  NA          0    NA    NA   NA       NA    NA
-#>  5 MANBID.1006  -0.0219     1    NA    30.6  4.56 18849 20515
-#>  6 EUGSTA.1007   0.222      1    NA    55    4.50 18891 20534
-#>  7 MANBID.1007  -0.111      1    NA    15    4.50 18892 20535
-#>  8 MATDOM.1007   0          1    NA   240    4.50 18891 20535
-#>  9 MICPRA.1007  NA          0    NA    NA   NA       NA    NA
-#> 10 SLOBER.1007  NA          0    NA    NA   NA       NA    NA
-#> # ... with 26,197 more rows
-
-
-

Exploring the distribution of status and tree diameter

-

Two columns that are commonly useful in ForestGEO datasets are status and dbh (diameter at breast height). We will begin by better understanding what type of variables they are. For this, base R provides useful functions.

-

status is a categorical variable.

- -

We can count the number of observations in each category with table(), then visualize the result with barplot().

- -

-

dbh is a continuous numeric variable.

- -

(Note the missing values (NAs).)

-

And we can visualize its distribution with hist().

- -

-

Unfortunately hist() dropped missing values silently. But we can better understand how missing values of dbh relate to status by extracting only the columns dbh and status, and picking only the rows where dbh is missing.

- -

Another approach is to count missing values.

- -

We learn that dbh is missing where a tree is dead (status = D) or gone (status = G). This makes sense and, depending on the type of analysis we want to do, we may want to keep or remove missing values.

-
-
-

Determining tree status based on stem status

-

Now we are ready to clean the data. For example, we can pick trees which status is “A” (alive). At ForestGEO, working with status is so common that fgeo provides a specialized function.

- -

In stem6, the variable status records the status of each individual stem. How can we determine the status of a tree based on the status of each of its stems? That is the job of add_status_tree().

- -
-
-

Picking a dbh range

-

Another very common task when working with ForestGEO data is to pick stems of a particular dbh range.

- -

Pick stems of 10 mm or more.

- -
-
-

Calculating abundance

-

Calculate the total abundance of stems and trees.

- -

Calculate the abundance of trees by species.

- -
-
-

Picking the most abundant species

-

What are the three most abundant tree species?

- -

Now we can pick the alive_trees of only the top3 species.

- -
-
-

Mapping the distribution of tree species

-

fgeo includes some functions specialized in mapping ForestGEO’s data.

- -

Map the most abundant species.

- -

-

Tweak to focus on the hectare available in the data.

- -

-
-
-

Species-habitat associations

-
tree <- download_data("luquillo_tree5_random")
-elevation <- download_data("luquillo_elevation")
-
-# Pick alive trees, of 10 mm or more
-census <- filter(tree, status == "A", dbh >= 10)
-
-# Pick sufficiently abundant species
-pick <- filter(add_count(census, sp), n > 50)
-species <- unique(pick$sp)
-
-# Use your habitat data or create it from elevation data
-habitat <- fgeo_habitat(elevation, gridsize = 20, n = 4)
-
-# A list or matrices
-tt_lst <- tt_test(census, species, habitat)
-#> Using `plotdim = c(320, 500)`. To change this value see `?tt_test()`.
-#> Using `gridsize = 20`. To change this value see `?tt_test()`.
-tt_lst
-#> [[1]]
-#>        N.Hab.1 Gr.Hab.1 Ls.Hab.1 Eq.Hab.1 Rep.Agg.Neut.1 Obs.Quantile.1
-#> CASARB      35     1508       90        2              0         0.9425
-#>        N.Hab.2 Gr.Hab.2 Ls.Hab.2 Eq.Hab.2 Rep.Agg.Neut.2 Obs.Quantile.2
-#> CASARB      24      433     1162        5              0       0.270625
-#>        N.Hab.3 Gr.Hab.3 Ls.Hab.3 Eq.Hab.3 Rep.Agg.Neut.3 Obs.Quantile.3
-#> CASARB      11      440     1157        3              0          0.275
-#>        N.Hab.4 Gr.Hab.4 Ls.Hab.4 Eq.Hab.4 Rep.Agg.Neut.4 Obs.Quantile.4
-#> CASARB       8      774      824        2              0        0.48375
-#> 
-#> [[2]]
-#>        N.Hab.1 Gr.Hab.1 Ls.Hab.1 Eq.Hab.1 Rep.Agg.Neut.1 Obs.Quantile.1
-#> PREMON      94     1511       87        2              0       0.944375
-#>        N.Hab.2 Gr.Hab.2 Ls.Hab.2 Eq.Hab.2 Rep.Agg.Neut.2 Obs.Quantile.2
-#> PREMON      97     1403      196        1              0       0.876875
-#>        N.Hab.3 Gr.Hab.3 Ls.Hab.3 Eq.Hab.3 Rep.Agg.Neut.3 Obs.Quantile.3
-#> PREMON      39      212     1386        2              0         0.1325
-#>        N.Hab.4 Gr.Hab.4 Ls.Hab.4 Eq.Hab.4 Rep.Agg.Neut.4 Obs.Quantile.4
-#> PREMON      15       64     1535        1              0           0.04
-#> 
-#> [[3]]
-#>        N.Hab.1 Gr.Hab.1 Ls.Hab.1 Eq.Hab.1 Rep.Agg.Neut.1 Obs.Quantile.1
-#> SLOBER      21      413     1183        4              0       0.258125
-#>        N.Hab.2 Gr.Hab.2 Ls.Hab.2 Eq.Hab.2 Rep.Agg.Neut.2 Obs.Quantile.2
-#> SLOBER      25      558     1040        2              0        0.34875
-#>        N.Hab.3 Gr.Hab.3 Ls.Hab.3 Eq.Hab.3 Rep.Agg.Neut.3 Obs.Quantile.3
-#> SLOBER      21     1289      309        2              0       0.805625
-#>        N.Hab.4 Gr.Hab.4 Ls.Hab.4 Eq.Hab.4 Rep.Agg.Neut.4 Obs.Quantile.4
-#> SLOBER       8      833      764        3              0       0.520625
-
-# A simple summary to help you interpret the results
-summary(tt_lst)
-#>   Species Habitat_1 Habitat_2 Habitat_3 Habitat_4
-#> 1  CASARB   neutral   neutral   neutral   neutral
-#> 2  PREMON   neutral   neutral   neutral   neutral
-#> 3  SLOBER   neutral   neutral   neutral   neutral
-
-# A combined matrix
-Reduce(rbind, tt_lst)
-#>        N.Hab.1 Gr.Hab.1 Ls.Hab.1 Eq.Hab.1 Rep.Agg.Neut.1 Obs.Quantile.1
-#> CASARB      35     1508       90        2              0       0.942500
-#> PREMON      94     1511       87        2              0       0.944375
-#> SLOBER      21      413     1183        4              0       0.258125
-#>        N.Hab.2 Gr.Hab.2 Ls.Hab.2 Eq.Hab.2 Rep.Agg.Neut.2 Obs.Quantile.2
-#> CASARB      24      433     1162        5              0       0.270625
-#> PREMON      97     1403      196        1              0       0.876875
-#> SLOBER      25      558     1040        2              0       0.348750
-#>        N.Hab.3 Gr.Hab.3 Ls.Hab.3 Eq.Hab.3 Rep.Agg.Neut.3 Obs.Quantile.3
-#> CASARB      11      440     1157        3              0       0.275000
-#> PREMON      39      212     1386        2              0       0.132500
-#> SLOBER      21     1289      309        2              0       0.805625
-#>        N.Hab.4 Gr.Hab.4 Ls.Hab.4 Eq.Hab.4 Rep.Agg.Neut.4 Obs.Quantile.4
-#> CASARB       8      774      824        2              0       0.483750
-#> PREMON      15       64     1535        1              0       0.040000
-#> SLOBER       8      833      764        3              0       0.520625
-
-# A dataframe
-to_df(tt_lst)
-#> # A tibble: 12 x 8
-#>    habitat sp     N.Hab Gr.Hab Ls.Hab Eq.Hab Rep.Agg.Neut Obs.Quantile
-#>  * <chr>   <chr>  <dbl>  <dbl>  <dbl>  <dbl>        <dbl>        <dbl>
-#>  1 1       CASARB    35   1508     90      2            0        0.942
-#>  2 2       CASARB    24    433   1162      5            0        0.271
-#>  3 3       CASARB    11    440   1157      3            0        0.275
-#>  4 4       CASARB     8    774    824      2            0        0.484
-#>  5 1       PREMON    94   1511     87      2            0        0.944
-#>  6 2       PREMON    97   1403    196      1            0        0.877
-#>  7 3       PREMON    39    212   1386      2            0        0.132
-#>  8 4       PREMON    15     64   1535      1            0        0.04 
-#>  9 1       SLOBER    21    413   1183      4            0        0.258
-#> 10 2       SLOBER    25    558   1040      2            0        0.349
-#> 11 3       SLOBER    21   1289    309      2            0        0.806
-#> 12 4       SLOBER     8    833    764      3            0        0.521
-
- - - - - - - - From 7f4257a6c0da9c0ff3700a293e7a0c6d3bd36547 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Feb 2019 16:30:12 -0500 Subject: [PATCH 2/3] Travis build no longer passes with failure on R 3.2 All fgeo packages should now work on 3.2 --- .travis.yml | 2 -- NEWS.md | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8bc7bd1..f841035 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,4 @@ matrix: - r: oldrel - r: 3.3 - r: 3.2 - allow_failures: - - r: 3.2 diff --git a/NEWS.md b/NEWS.md index f6ea639..093bae5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,6 @@ * Tidy dependencies. -# fgeo 1.0.0 ([GitHub](https://github.com/forestgeo/fgeo/releases) release) +# fgeo 1.0.0 ([GitHub](https://github.com/forestgeo/fgeo/releases)) * Internal release. From 656c3d98e7155dc028762e7353b17d7d0f19a18b Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Feb 2019 16:31:39 -0500 Subject: [PATCH 3/3] Tidy description --- DESCRIPTION | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b49eff5..3a88295 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -104,10 +104,10 @@ Imports: cli (>= 1.0.1), crayon (>= 1.3.4), dplyr (>= 0.7.8), - fgeo.analyze (>= 1.1.2), - fgeo.plot (>= 1.1.1), - fgeo.tool (>= 1.2.1), - fgeo.x (>= 1.1.0), + fgeo.analyze (>= 1.1.3), + fgeo.plot (>= 1.1.3), + fgeo.tool (>= 1.2.2), + fgeo.x (>= 1.1.2), glue (>= 1.3.0), magrittr (>= 1.5), purrr (>= 0.3.0), @@ -117,11 +117,11 @@ Imports: Suggests: covr (>= 3.2.1), DT (>= 0.5), + kableExtra (>= 1.0.1), knitr (>= 1.21), rmarkdown (>= 1.11), spelling (>= 2.0), - testthat (>= 2.0.1), - kableExtra + testthat (>= 2.0.1) Additional_repositories: https://forestgeo.github.io/drat/ Encoding: UTF-8 Language: en-US