Skip to content

Commit

Permalink
switched to roxygen2 docs, more work on get_lb and get_ue0
Browse files Browse the repository at this point in the history
  • Loading branch information
pboesu committed Dec 27, 2017
1 parent 4275ad2 commit 715fb91
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 32 deletions.
1 change: 1 addition & 0 deletions DEButilities.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ Description: Functions copied from the DEBtool_R git repository and repackaged i
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Suggests: testthat
6 changes: 5 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
exportPattern("^[[:alpha:]]+")
# Generated by roxygen2: do not edit by hand

export(dget_tb)
export(get_tb)
export(get_ue0)
35 changes: 29 additions & 6 deletions R/get_tb.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
## get_tb
#

##
get_tb= function(p, eb = 1, lb=NA){
#' get_tb
#'
#' Obtains scaled age at birth, given the scaled reserve density at birth.
#' Divide the result by the somatic maintenance rate coefficient to arrive at age at birth.
#'
#' @param p 1 or 3-vector with parameters g, k_J/ k_M, v_H^b; Last 2 values are optional in invoke call to get_lb
#' @param eb optional scalar with scaled reserve density at birth (default eb = 1)
#' @param lb optional scalar with scaled length at birth (default: lb is obtained from get_lb)
#'
#' @author Bas Kooijman
#'
#' @return 3-element vector containing tb: scaled age at birth tau_b = a_b k_M; lb: scalar with scaled length at birth: L_b/ L_m; info: indicator equals 1 if successful, 0 otherwise
#' @export
#'
#' @examples
#' get_tb(p = c(.1,.5,.03))
get_tb <- function(p, eb = 1, lb=NA){
# created at 2007/07/27 by Bas Kooijman; modified 2014/03/17, 2015/01/18

## Syntax
Expand Down Expand Up @@ -42,7 +55,7 @@ get_tb= function(p, eb = 1, lb=NA){

info = 1

if (!exists('lb')) {
if (is.na(lb)) {
if (length(p) < 3){
print('not enough input parameters, see get_lb \n')
tb = NA
Expand Down Expand Up @@ -70,7 +83,17 @@ get_tb= function(p, eb = 1, lb=NA){

# subfunction

dget_tb= function(x, abxb){
#' dget_tb
#'
#' Subroutine called by get_tb
#'
#' @param x x
#' @param abxb abxb
#'
#' @return f
#' @export
#'
dget_tb <- function(x, abxb){
# called by get_tb
ab=abxb[1]
xb=abxb[2]
Expand Down
63 changes: 38 additions & 25 deletions R/get_ue0.R
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
## get_ue0
# gets initial scaled reserve

##
# function [uE0, lb, info] =
get_ue0=function(p, eb, lb0){
#' get_ue0
#'
#' gets initial scaled reserve.
#' Obtains the initial scaled reserve for eggs given the scaled reserve density at birth.
#' Specification of length at birth as third input by-passes its computation, so if you want to specify an initial value for this quantity, you should use get_lb directly.
#'
#' @param p 1 or 3 -vector with parameters g, k_J/ k_M, v_H^b, see get_lb
#' @param eb optional scalar with scaled reserbe density at birth (default: eb = 1)
#' @param lb0 optional scalar with scaled length at birth (default: lb is optained from get_lb)
#'
#' @return [uE0, lb, info] scaled with scaled reserve at t=0: $U_E^0 g^2 k_M^3/ v^2$ with $U_E^0 = M_E^0/ \{J_{EAm}\}$; lb: scalar with scaled length at birth; info: indicator equals 1 if successful, 0 otherwise
#' @export
#'
#' @examples
#' g = 6; k = 6; kap = .8; uHb = .001; vHb = uHb/ (1 - kap);
#' par = c(g, k, vHb);
get_ue0=function(p, eb = 1, lb0 = NA){
# created at 2007/07/27 by Bas Kooijman; modified 2010/05/02

## Syntax
# [uE0, lb, info] = <../get_ue0.m *get_ue0*>(p, eb, lb0)

## Description
# Obtains the initial scaled reserve given the scaled reserve density at birth.
# Function get_ue0 does so for eggs, get_ue0_foetus for foetuses.
# Specification of length at birth as third input by-passes its computation,
# so if you want to specify an initial value for this quantity, you should use get_lb directly.
# Obtains the initial scaled reserve given the scaled reserve density at birth.
# Function get_ue0 does so for eggs, get_ue0_foetus for foetuses.
# Specification of length at birth as third input by-passes its computation,
# so if you want to specify an initial value for this quantity, you should use get_lb directly.
#
# Input
#
# * p: 1 or 3 -vector with parameters g, k_J/ k_M, v_H^b, see get_lb
# * eb: optional scalar with scaled reserbe density at birth
# * eb: optional scalar with scaled reserbe density at birth
# (default: eb = 1)
# * lb0: optional scalar with scaled length at birth
# * lb0: optional scalar with scaled length at birth
# (default: lb is optained from get_lb)
#
# Output
#
# * uE0: scaled with scaled reserve at t=0: $U_E^0 g^2 k_M^3/ v^2$
# * uE0: scaled with scaled reserve at t=0: $U_E^0 g^2 k_M^3/ v^2$
# with $U_E^0 = M_E^0/ \{J_{EAm}\}$
# * lb: scalar with scaled length at birth
# * info: indicator equals 1 if successful, 0 otherwise

## Remarks
# See <get_ue0_foetus.html *get_ue0_foetus*> for foetal development.
# See <initial_scaled_reserve.html *initial_scaled_reserve*>, for a non-dimensionless scaling.

## Example of use
# see <../mydata_ue0.m *mydata_ue0*>
if (!exists('eb')) {
eb = 1 # maximum value as juvenile
}
if (!exists('lb0')){

# if (!exists('eb')) {
# eb = 1 # maximum value as juvenile
# }

if (is.na(lb0)){
if (length(p) < 3) {
print('not enough input parameters, see get_lb \n');
uE0 = NA
Expand All @@ -56,12 +67,14 @@ get_ue0=function(p, eb, lb0){
info = 1
}


# unpack p
g = p[1] # energy investment ratio

xb = g/ (eb + g)
uE0 = (3 * g/ (3 * g * xb^(1/ 3)/ lb - beta0(0, xb)))^3

print(paste("uE0", uE0))

return(c(uE0, lb, info))
}
19 changes: 19 additions & 0 deletions man/dget_tb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions man/get_tb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions man/get_ue0.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 715fb91

Please sign in to comment.