Skip to content

Commit

Permalink
Fixing issue renatoamorais#1 v2
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoamorais committed Jun 1, 2020
1 parent 6113386 commit 32fc677
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 172 deletions.
Binary file modified .DS_Store
Binary file not shown.
298 changes: 158 additions & 140 deletions .Rapp.history
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
zd <- zy / 365
zd
my <- 1 - exp (-zy)
my
md <- 1 - exp (-zd)
md
mvec
my
md
vbf
tf
lvec
Expand Down Expand Up @@ -824,152 +815,179 @@ devtools::create(file.path (getwd (), "rfishprod"))
devtools:::create(file.path (getwd (), "/rfishprod"))
devtools:::create
devtools:::create("path/to/package/pkgname")
library (devtools)
devtools::load_all()
pkgpath <- file.path (getwd(), 'rfishprod')
pkgpath
devtools::load_all(pkgpath)
repdata
head(db)
?install
library (devtools)#
library (usethis)#
library (roxygen2)#
library (tidyverse)#
library (rmarkdown)
path <- file.path (getwd (), 'rfishprod')#
#usethis::create_package (path)#
setwd (path)#
## Loading everything ###
devtools::load_all()#
#
## Active project ###
proj_activate(path)#
#
## Altering description file ###
use_description (fields = list (#
Package = 'rfishprod',#
Version = '0.0.0.9100',#
Title = 'Estimating Reef Fish Productivity',#
`Authors@R` = 'person ("Renato", "Morais", email = "[email protected]",#
role = c ("aut", "cre"), #
comment = c(ORCID = "https://orcid.org/0000-0003-4652-6676"))',#
Description = 'Implements a framework to generate individual-level estimates of fish productivity, with a focus on reef fishes. This individual approach works by combining estimates of somatic growth through the von Bertalanffy Growth Model, and deterministic or stochastic natural mortality using instantaneous mortality rates.',#
Depends = 'R (>= 3.5)',#
URL = 'https://github.com/renatomoraisaraujo/rfishprod',#
LazyData = FALSE))
use_mit_license(name = "Renato Morais")
use_package('xgboost', 'Depends')#
use_package('scales', 'Imports')#
use_package('stats', 'Imports')#
use_package('rlang', 'Imports')
use_r ('db')
findir <- file.path (sub ("Ch5 Review on fish productivity/rfishprod", 'Ch1 Fundamental drivers of fish growth', getwd()))
devtools::document()
devtools::load_all()
devtools::check()
pkgpath <- file.path (getwd(), 'rfishprod')#
#
#devtools::load_all(pkgpath)#
devtools::install(pkgpath)
pkgpath
?install
as.package(pkgpath)
devtools::install(as.package(pkgpath))
library (rfishprod)
repdata
db
rfishprod:::repdata
db
data('db')
db
ls()
rm(db)
db
data(db)
ls()
ls(loadNamespace('rfishprod'))
use_r ('predicting_growth')
use_r ('auxiliary')
.onLoad
?data
devtools::check()
?data
use_description (fields = list (#
Package = 'rfishprod',#
Version = '0.0.0.9100',#
Title = 'Estimating Reef Fish Productivity',#
`Authors@R` = 'person ("Renato", "Morais", email = "[email protected]",#
role = c ("aut", "cre"), #
comment = c(ORCID = "https://orcid.org/0000-0003-4652-6676"))',#
Description = 'Implements a framework to generate individual-level estimates of fish productivity, with a focus on reef fishes. This individual approach works by combining estimates of somatic growth through the von Bertalanffy Growth Model, and deterministic or stochastic natural mortality using instantaneous mortality rates.',#
Depends = 'R (>= 3.5)',#
URL = 'https://github.com/renatomoraisaraujo/rfishprod',#
LazyData = FALSE))
use_mit_license(name = "Renato Morais")
use_package('xgboost', 'Depends')#
use_package('scales', 'Imports')#
use_package('stats', 'Imports')#
use_package('rlang', 'Imports')#
use_packages('utils', 'Imports')
use_package('utils', 'Imports')
devtools::load_all()
devtools::check()
devtools::document()
devtools::load_all()
devtools::check()
head(db)
environment()
ls()
ls(loadNamespace='rfishprod')
ls(loadNamespace('rfishprod'))
parent.env(environment())
utils::data(db, envir=parent.env(environment()))
utils::data(db, package = 'rfishprod', envir=parent.env(environment()))
head(db)
rm(db)
repdata
xgboostparams
detach(xgboostparams)
detach('xgboostparams')
use_r ('auxiliary')
?vegan
library(vegan)
library(cars)
?iris
iris
?data
data(db)
dataset <- data (db)
head(dataset)
dataste
dataset
data(db, envir = environment())
head(db)
rm(db)
data(db, package = 'rfishprod')
head(db)
rm(db)
getwd()
remove.packages('rfishprod')
library (devtools)
pkgpath <- file.path (getwd(), 'rfishprod')
devtools::install(as.package(pkgpath))
library (rfishprod)
ls()
devtools::check()
list.files()
load('DESCRIPTION')
read.txt('DESCRIPTION')
apropos('read')
aff <- read.file ('DESCRIPTION')
aff <- read_file ('DESCRIPTION')
aff
packageVersion('rfishprod')
devtools::document()
devtools::document()
devtools::document()
devtools::document()
devtools::check()
?packageVersion
?packageStartupMessage
devtools::document()
devtools::check()
render ('README.Rmd')
head(db)
repdata
rfishprod:::repdata
(repdata <- rfishprod:::repdata)
repdata <- tidytrait (repdata, db)
remove.packages('rfishprod')
library (devtools)
pkgpath <- file.path (getwd(), 'rfishprod')
devtools::install(as.package(pkgpath))
library (rfishprod)
ls()
remove.packages('rfishprod')
library (devtools)#
#
pkgpath <- file.path (getwd(), 'rfishprod')#
#
#devtools::load_all(pkgpath)#
devtools::install(as.package(pkgpath))
library (rfishprod)
ls()
(repdata <- rfishprod:::repdata)
repdata <- tidytrait (repdata, db)
fmod <- formula (~ sstmean + MaxSizeTL + Diet + Position + Method)
xgboostparams
remove.packages('rfishprod')
library (devtools)#
#
pkgpath <- file.path (getwd(), 'rfishprod')#
#
#devtools::load_all(pkgpath)#
devtools::install(as.package(pkgpath))#
#
library (rfishprod)
ls()
(repdata <- rfishprod:::repdata)#
#
# Getting levels ready ##
repdata <- tidytrait (repdata, db)#
#
# Formula from Morais and Bellwood (2018) ##
fmod <- formula (~ sstmean + MaxSizeTL + Diet + Position + Method)#
#
# Predicting Kmax per se (in reality, use 100s to 1000 iterations) ##
datagr <- predKmax (repdata, #
dataset = db, #
fmod = fmod, #
niter = 10, #
return = 'pred')
predKmax
rlang::.data
remove.packages('rfishprod')
library (devtools)#
#
pkgpath <- file.path (getwd(), 'rfishprod')#
#
#devtools::load_all(pkgpath)#
devtools::install(as.package(pkgpath))
library (rfishprod)
ls()
predKmax
(repdata <- rfishprod:::repdata)
repdata <- tidytrait (repdata, db)
fmod <- formula (~ sstmean + MaxSizeTL + Diet + Position + Method)
datagr <- predKmax (repdata, dataset = db,#
fmod = fmod,#
params = xgboostparams,#
niter = 10,#
return = 'pred')
datagr <- predKmax (repdata, #
dataset = db, #
fmod = fmod, #
niter = 10, #
return = 'pred')
datagr
datagr <- datagr$pred
datagr$Md <- with (datagr,#
predM (Lmeas = Size,#
Lmax = MaxSizeTL,#
Kmax = Kmax,#
Lr = 1,#
temp = sstmean,#
method = 'Gislason'))
datagr$Md
datagr$Md <- with (datagr,#
predM (Lmeas = Size,#
Lmax = MaxSizeTL,#
Kmax = Kmax,#
method = 'Gislason'))
datagr$Md
with (datagr, applyVBGF (Lmeas = Size,#
Lmax = MaxSizeTL,#
Kmax = Kmax))
datagr$Md <- with (datagr, #
predM (Lmeas = Size, #
Lmax = MaxSizeTL, #
Kmax = Kmax, #
method = 'Gislason'))
with (datagr, applyVBGF (Lmeas = Size, #
Lmax = MaxSizeTL, #
Kmax = Kmax))
datagr$Size
sogr <- with(datagr, somaGain (a = a,#
b = b,#
Lmeas = Size,#
Lmax = MaxSizeTL,#
Kmax = Kmax))
b = b,#
Lmeas = Size, #
Lmax = MaxSizeTL, #
Kmax = Kmax))
sogr
applyMstoch (datagr$Md)
loss <- with(datagr, somaLoss (M = Md,#
Lmeas = Size,#
a = a,#
b = b))
Lmeas = Size,#
a = a,#
b = b))
loss
with(datagr, somaGain (a = a,#
b = b,#
Lmeas = Size, #
Lmax = MaxSizeTL, #
Kmax = Kmax))
with(datagr, somaLoss (M = Md,#
Lmeas = Size,#
a = a,#
b = b))
rmarkdown::render ('README.Rmd')
library (devtools)#
library (usethis)#
library (roxygen2)#
library (tidyverse)#
library (rmarkdown)#
##!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!###
## TO DO LIST (on 16 July 2019) on 28 May 2020 ###
## --Add tests ###
## --Further fill in package documentation ###
## --Add vignette (simplify the Readme file and basically ###
## that will become the vignette, although plotting the ###
## Suppl Fig from the Funct Ecol paper would be nice) ###
## --Fix xgboost parameters use ###
## ###
##!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!###
## A path for the package and creating the skeleton ###
path <- file.path (getwd (), 'rfishprod')#
#usethis::create_package (path)#
setwd (path)#
## Loading everything ###
devtools::load_all()#
#
## Active project ###
proj_activate(path)
rmarkdown::render ('README.Rmd')
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Depends:
R (>= 3.5),
xgboost
Encoding: UTF-8
LazyData: FALSE
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0
Imports:
Expand Down
3 changes: 3 additions & 0 deletions R/.Rapp.history
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.data
rlang::.data)
rlang::.data
18 changes: 11 additions & 7 deletions R/predicting_growth.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,26 @@

predKmax <- function(traits, dataset, fmod, params = NULL, niter, nrounds = 150, verbose = 0, print_every = 1000, return = c('pred', 'relimp', 'models'), lowq = 0.25, uppq = 0.75) {

if (identical (dataset, rlang::.data)) {

if (missing (dataset)) {
dataset <- db
}


if (is.null (params)) {

if (identical (dataset, db)) {

params <- xgboostparams

} else if (is.null (params)) {
} else {

params <- list ()
warning('Consider optimising xgboost parameters with xgb.train')

}
}

if (missing (dataset)) {

dataset <- db

}

modmatnd <- stats::model.matrix(fmod, data = traits) [, -1]
modmat <- stats::model.matrix(fmod, dataset) [, -1]
Expand Down
6 changes: 4 additions & 2 deletions R/rfishprod-package.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#' @keywords internal
"_PACKAGE"
#' @name rfishprod-package
#' @docType package
#' @section \code{rfishprod} functions:

#' Use the functions \code{predKmax} and \code{predM} to predict growth and mortality trajectories, respectively. Then, use \code{somaGain}, \code{applyMstoch} and \code{somaLoss} to position your fishes in these trajectories and estimate components of productivity!
#' @docType package


.onLoad <- function(libname, pkgname) {
utils::data("db", package=pkgname, envir=parent.env(environment()))
utils::data(db, package=pkgname)
}

#utils::data(db, package=pkgname, envir=parent.env(environment()))

.onAttach <- function(libname, pkgname) {
v <- utils::packageVersion(pkgname)
Expand Down
Loading

0 comments on commit 32fc677

Please sign in to comment.