GotelliLab / EcoSimR

Repository for EcoSimR, by Gotelli, N.J. , Hart E. M. and A.M. Ellison. 2014. EcoSimR 0.1.0
http://ecosimr.org
Other
27 stars 10 forks source link

null_model_engine not finding algo functions #16

Closed ngotelli closed 10 years ago

ngotelli commented 10 years ago

The following code works for setting up and getting into dev mode:

# Help system set up
# Code from Ted for updating EcoSimR help system
#30 July 2014

# caution: next line appears to reinstall from 
# github and will probably wipe out changes 
# unless they were first committed and pushed
#------------------------------
# install_github("EcoSimR","gotellilab",ref="dev")
#------------------------------

# Add devtools and roxygen and pbapply libraries
library(devtools)
library(roxygen2)
library(pbapply)

# Set path for location of EcoSimR main folder
path <- "C:/Users/Administrator/Documents/GitHub/EcoSimR"

# enter develop mode ON
dev_mode()

# Rebuild files and reinstall library
roxygenize(path)
install(path)

# Open library
library(EcoSimR)

However, at this point, the example code in the help documentation for null_model_engine is failing:

d> data(macwarb)
Warning message:
In data(macwarb) : data set ‘macwarb’ not found

d> data(macwarblers) # but this works OK

d> null_model_engine(macwarb)
Error in parse(text = algo) : argument "algo" is missing, with no default

d> null_model_engine(macwarb,algo="RA1")
Error in eval(expr, envir, enclos) : object 'RA1' not found

d> null_model_engine(macwarblers)
Error in null_model_engine(macwarblers) : object 'macwarblers' not found

d> null_model_engine(macwarblers,algo="RA2")
Error in null_model_engine(macwarblers, algo = "RA2") : 
  object 'macwarblers' not found
emhart commented 10 years ago

I'd say that's because you're trying to use the null_model_engine fxn, which I've tried to obscure from the user in the hopes of making it more user friendly. So this should run fine:

warbMod <- niche_null_model(macwarb)
summary(warbMod)
plot(warbMod,type="niche")
plot(warbMod, type="hist")

Your other issue is that I tried to use more standard R conventions for fxn names, so RA1 is actually ra1. You can see from the fxn wrappers that I match the arguments and convert them to the actual names which I then pass to the main null_model_engine

niche_null_model <- function(species_data, algo = "ra3", metric = "Pianka", n.reps = 1000, row.names = TRUE, random.seed = 0){
  a.choice <- c("ra1","ra2","ra3","ra4")
  m.choice <- c("Pianka", "Czekanowski", "Pianka.var", "Czekanowski.var", "Pianka.skew", "Czekanowski.skew")
  m.func <- c("pianka", "czekanowski", "pianka_var", "czekanowski_var", "pianka_skew", "czekanowski_skew")
  algo <- match.arg(algo,choices = a.choice)
  metric <- match.arg(metric,choices = m.choice)

  #Now do the substitutions
  metric <- m.func[which(m.choice==metric)]
amellison17 commented 10 years ago

Ted - I am very glad to see that you are using good R programming conventions! Nick and I can learn a lot from this.

Best, Aaron

From: Edmund Hart [mailto:notifications@github.com] Sent: Friday, August 01, 2014 12:57 PM To: GotelliLab/EcoSimR Subject: Re: [EcoSimR] null_model_engine not finding algo functions (#16)

I'd say that's because you're trying to use the null_model_engine fxn, which I've tried to obscure from the user in the hopes of making it more user friendly. So this should run fine:

warbMod <- niche_null_model(macwarb)

summary(warbMod)

plot(warbMod,type="niche")

plot(warbMod, type="hist")

Your other issue is that I tried to use more standard R conventions for fxn names, so RA1 is actually ra1. You can see from the fxn wrappers that I match the arguments and convert them to the actual names which I then pass to the main null_model_engine

niche_null_model <- function(species_data, algo = "ra3", metric = "Pianka", n.reps = 1000, row.names = TRUE, random.seed = 0){

a.choice <- c("ra1","ra2","ra3","ra4")

m.choice <- c("Pianka", "Czekanowski", "Pianka.var", "Czekanowski.var", "Pianka.skew", "Czekanowski.skew")

m.func <- c("pianka", "czekanowski", "pianka_var", "czekanowski_var", "pianka_skew", "czekanowski_skew")

algo <- match.arg(algo,choices = a.choice)

metric <- match.arg(metric,choices = m.choice)

Now do the substitutions

metric <- m.func[which(m.choice==metric)]

— Reply to this email directly or view it on GitHubhttps://github.com/GotelliLab/EcoSimR/issues/16#issuecomment-50908445.

ngotelli commented 10 years ago

Many thanks Ted! I was working off the example code that is shown in the null_model_engine help, which lists the choices as RA1, RA2, etc. I will clean that up as I start to work through all of the functions.

Aaron is right, we are going to learn a lot of good programming tools working with you on this.