From efee0aa085804ea258cfb58c91b8149912b87217 Mon Sep 17 00:00:00 2001 From: Igor Cobelo Date: Thu, 25 Jun 2020 23:21:25 -0300 Subject: [PATCH] nv --- DESCRIPTION | 6 +- NAMESPACE | 8 +-- R/indvol.R | 156 ++++++++++++++++++++++++++------------------------ man/indvol.Rd | 7 ++- 4 files changed, 90 insertions(+), 87 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ace799e..60b8a37 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,12 +5,12 @@ Version: 0.1.0 Author: Igor Cobelo Ferreira Maintainer: Igor Cobelo Ferreira Description: The functions return the volumetric and phytosociological sampling parameters for forest inventories. -License: GPL-3.0 +License: GPL(>=3) Encoding: UTF-8 LazyData: TRUE Citation: https://github.com/igorcobelo/forestry/blob/master/inst/citation -Depends: - R(>= 3.5.0), +Depends: R(>= 3.5.0) +Imports: BiodiversityR, cowplot, data.table, diff --git a/NAMESPACE b/NAMESPACE index 9cf5463..ce8a9e8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,5 @@ # Generated by roxygen2: do not edit by hand -export(fito) -export(indvol) -export(acs) -export(ace) -export(bit) \ No newline at end of file +export(fito,indvol,ace,acs,bit) +importFrom('BiodiversityR', 'cowplot', 'data.table', 'dplyr', 'flextable', 'ggplot2', + 'officer', 'rvg', 'tidyr', 'tidyverse') \ No newline at end of file diff --git a/R/indvol.R b/R/indvol.R index 77175f1..a2e0932 100644 --- a/R/indvol.R +++ b/R/indvol.R @@ -66,7 +66,7 @@ indvol <- function(x, mens="plot", vol=F, myeq=NULL, veg=NULL, f=NULL, circ=F) { plan<-data.frame(p,row,s,h,d,volume, stringsAsFactors = F) }else{ - plan<-data.frame(p,row,s,h,d, stringsAsFactors = F) + plan<-data.frame(p,row,s,h,d, stringsAsFactors = F) } } @@ -147,7 +147,7 @@ indvol <- function(x, mens="plot", vol=F, myeq=NULL, veg=NULL, f=NULL, circ=F) { plan<-data.frame(e,p,row,s,h,d,volume, stringsAsFactors = F) }else{ - plan<-data.frame(e,p,row,s,h,d, stringsAsFactors = F) + plan<-data.frame(e,p,row,s,h,d, stringsAsFactors = F) } } @@ -185,7 +185,7 @@ indvol <- function(x, mens="plot", vol=F, myeq=NULL, veg=NULL, f=NULL, circ=F) { h<- as.numeric(result2[!(result2==-Inf)]) row<- as.numeric(rownames(result2)[!(result2==-Inf)]) - + #ESPECIES x[,2]<-as.character(x[,2]) @@ -200,18 +200,18 @@ indvol <- function(x, mens="plot", vol=F, myeq=NULL, veg=NULL, f=NULL, circ=F) { #VOLUME if(vol==T){ - resultvol<-as.numeric() - for(i in x[,1]){ - resultvol[i]<-sum(subset(x[,5], x[,1]==i)) - } - resultvol<-as.data.frame(resultvol) - - volume<- resultvol[!(is.na(resultvol))] - - plan<-data.frame(row,s,h,d,volume, stringsAsFactors = F) - + resultvol<-as.numeric() + for(i in x[,1]){ + resultvol[i]<-sum(subset(x[,5], x[,1]==i)) + } + resultvol<-as.data.frame(resultvol) + + volume<- resultvol[!(is.na(resultvol))] + + plan<-data.frame(row,s,h,d,volume, stringsAsFactors = F) + }else{ - plan<-data.frame(row,s,h,d, stringsAsFactors = F) + plan<-data.frame(row,s,h,d, stringsAsFactors = F) } } @@ -230,75 +230,79 @@ indvol <- function(x, mens="plot", vol=F, myeq=NULL, veg=NULL, f=NULL, circ=F) { plan<-x } - - if(vol==F){ - #Para myeq: - - if(!(is.null(myeq))){ - - plan$`Volume (m3)` <- eval(substitute(myeq), envir=plan); plan - } - #Para fator de forma (hf): - - if(!(is.null(f))){ - plan$`Volume (m3)`<-(pi*d^2/40000)*h*f - } - - #Para veg: - if(!is.null(veg)){ - - if(veg=="cerrado"){ - plan$`Volume (m3)`<-0.000065661*d^(2.475293)* h^(0.300022) - } - if(veg=="cer_regen"){ - plan$`Volume (m3)`<-0.000058468*d^(2.160042)* h^(0.791208) - } - - if(veg=="campo_cer"){ - plan$`Volume (m3)`<-0.000024059*d^(2.506122)* h^(0.929214) - } - - if(veg=="cerradao"){ - plan$`V (m3)`<-0.000094001*d^(1.830398)* h^(0.960913) - } - - if(veg=="mata_pri"){ - plan$`Volume (m3)`<-0.00024502*d^(2.265786)* h^(0.150001) - } - - if(veg=="mata_sec"){ - plan$`Volume (m3)`<-0.000074230*d^(1.707348)* h^(1.16873) - } - - if(veg=="mata_ciliar"){ - plan$`Volume (m3)`<-0.000065607*d^(2.084676)* h^(0.752177) - } - - if(veg=="mata_seca"){ - plan$`Volume (m3)`<-0.000074924*d^(1.818557)* h^(1.061157) - } + if(vol==F){ + #Para myeq: - if(veg=="trans_cipo"){ - plan$`Volume (m3)`<-0.0000065231*d^(1.64498)* h^(2.234673) + if(!(is.null(myeq))){ + + d<-plan$d + h<-plan$h + + plan$`Volume (m3)` <- eval(parse(text = as.character(myeq))) + } - if(veg=="trans_jaiba"){ - plan$`Volume (m3)`<-0.000057947*d^(1.911894)* h^(1.0751) - } + #Para fator de forma (hf): - if(veg=="caat_arborea"){ - plan$`Volume (m3)`<-0.0000408657*d^(2.235528)* h^(0.823993) + if(!(is.null(f))){ + plan$`Volume (m3)`<-(pi*d^2/40000)*h*f } - if(veg=="caat_arbustiva"){ - plan$`Volume (m3)`<-0.000075999*d^(2.016671)* h^(0.761177) + #Para veg: + if(!is.null(veg)){ + + if(veg=="cerrado"){ + plan$`Volume (m3)`<-0.000065661*d^(2.475293)* h^(0.300022) + } + if(veg=="cer_regen"){ + plan$`Volume (m3)`<-0.000058468*d^(2.160042)* h^(0.791208) + } + + if(veg=="campo_cer"){ + plan$`Volume (m3)`<-0.000024059*d^(2.506122)* h^(0.929214) + } + + if(veg=="cerradao"){ + plan$`V (m3)`<-0.000094001*d^(1.830398)* h^(0.960913) + } + + if(veg=="mata_pri"){ + plan$`Volume (m3)`<-0.00024502*d^(2.265786)* h^(0.150001) + } + + if(veg=="mata_sec"){ + plan$`Volume (m3)`<-0.000074230*d^(1.707348)* h^(1.16873) + } + + if(veg=="mata_ciliar"){ + plan$`Volume (m3)`<-0.000065607*d^(2.084676)* h^(0.752177) + } + + if(veg=="mata_seca"){ + plan$`Volume (m3)`<-0.000074924*d^(1.818557)* h^(1.061157) + } + + if(veg=="trans_cipo"){ + plan$`Volume (m3)`<-0.0000065231*d^(1.64498)* h^(2.234673) + } + + if(veg=="trans_jaiba"){ + plan$`Volume (m3)`<-0.000057947*d^(1.911894)* h^(1.0751) + } + + if(veg=="caat_arborea"){ + plan$`Volume (m3)`<-0.0000408657*d^(2.235528)* h^(0.823993) + } + + if(veg=="caat_arbustiva"){ + plan$`Volume (m3)`<-0.000075999*d^(2.016671)* h^(0.761177) + } + } } - } - colnames(plan)[1]<-colnames(x)[1] colnames(plan)[2]<-colnames(x)[2] @@ -312,7 +316,7 @@ indvol <- function(x, mens="plot", vol=F, myeq=NULL, veg=NULL, f=NULL, circ=F) { if(mens=="strata"){ colnames(plan)[6]<-colnames(x)[6] } - - return(plan) - -} + + return(plan) + +} \ No newline at end of file diff --git a/man/indvol.Rd b/man/indvol.Rd index e1fa868..e34219c 100644 --- a/man/indvol.Rd +++ b/man/indvol.Rd @@ -31,8 +31,9 @@ indvol(x, mens="plot", vol=F, myeq=NULL, veg=NULL, f=NULL, circ=F) } \item{vol}{Logical. If already have a volume column (last), vol=T. } - \item{myeq}{Optional. User can calculate a diferent equation using height (h) and diameter (d), e.g.: - 0.000065661*d^(2.475293)* h^(0.300022)} + \item{myeq}{Optional. User can calculate a diferent equation using height (h) and diameter (d), in quotes, e.g.: + "0.000065661*d^(2.475293)*h^(0.300022)" +} \item{veg}{Optional. A vegetable formation (equations for volume with bark): - "cerrado" (cerrado/brazilian savannah): 0.000065661*d^(2.475293)* h^(0.300022) @@ -95,7 +96,7 @@ head(simple1) #Using an equation entered manually -IF_simple <- indvol(x = simple1, mens="plot", myeq = 0.000065661*d^(2.475293)* h^(0.300022)) +IF_simple <- indvol(x = simple1, mens="plot", myeq = "0.000065661*d^2.475293*h^0.300022") #Using a form factor