From bdf78e1e6c63840d16fb7dc676b358e42d90eb4c Mon Sep 17 00:00:00 2001 From: baptiste Date: Wed, 4 Dec 2013 21:49:44 -0300 Subject: [PATCH] travis --- .Rbuildignore | 4 +++ .travis.yml | 32 +++++++++++++++++++++++ DESCRIPTION | 2 +- NAMESPACE | 2 +- NEWS | 5 ++++ R/drude.r | 43 +++++++++++++++++-------------- demo/AuJC.r | 4 +-- man/drude.Rd | 13 +++++----- man/{fitDrude.Rd => fit_drude.Rd} | 12 ++++----- 9 files changed, 82 insertions(+), 35 deletions(-) create mode 100644 .Rbuildignore create mode 100644 .travis.yml rename man/{fitDrude.Rd => fit_drude.Rd} (59%) diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..a72eb03 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,4 @@ +.gitignore +.git +.RS_Store +.travis.yml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..49b90ca --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +# Sample .travis.yml for R projects. +# +# See the r-travis repo and its wiki +# https://github.com/craigcitro/r-travis/wiki + +language: c + +env: + global: + - R_BUILD_ARGS="--no-build-vignettes --no-manual" + - R_CHECK_ARGS="--no-build-vignettes --no-manual --as-cran" + +before_install: + - curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh + - chmod 755 ./travis-tool.sh + - ./travis-tool.sh bootstrap + +install: + - ./travis-tool.sh install_r testthat knitr + +script: + - ./travis-tool.sh run_tests + +after_script: + - ./travis-tool.sh dump_logs + +notifications: + email: + on_success: change + on_failure: change + + diff --git a/DESCRIPTION b/DESCRIPTION index f912c9e..278597a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,7 @@ Authors@R: person("Baptiste", "Auguie", email = "baptiste.auguie@gmail.com", source listed in the help file.") Description: Physical constants. Gold, silver and glass permittivities, together with spline interpolation functions. -Version: 0.2.2 +Version: 0.2.3 Date: 2012-03-04 Depends: R (>= 2.13), diff --git a/NAMESPACE b/NAMESPACE index 5dfe161..5d55a55 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,4 +2,4 @@ export(dielectric2plot) export(drude) export(epsAg) export(epsAu) -export(fitDrude) +export(fit_drude) diff --git a/NEWS b/NEWS index 7ad0376..51122bf 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ + +dielectric 0.2.3 (2013-11-08) + +* silly typo in Au_JC demo + dielectric 0.2.2 (2013-05-18) * cleaning examples for CRAN diff --git a/R/drude.r b/R/drude.r index 32fd765..3de5269 100644 --- a/R/drude.r +++ b/R/drude.r @@ -2,41 +2,46 @@ ##' ##' a bacground contribution eps_inf is assumed for the core electrons ##' @title drude -##' @param wavelength wavelength in m -##' @param omega angular frequency in rad/s +##' @param wavelength wavelength in nm ##' @param p vector of 3 parameters +##' @param omega angular frequency in rad/s ##' @param omega_p plasma frequency in rad/s ##' @param gamma_p damping constant, in rad/s ##' @param epsilon_inf background dielectric function ##' @param ... not used -##' @return a data.frame with wavelength in microns and complex dielectric function +##' @return a data.frame with wavelength in nm and complex dielectric function ##' @author Baptiste Auguie ##' @export -drude <- function(wavelength, omega=NULL, p=c(1e16, 1e14, 1), +drude <- function(wavelength=633, p=c(1e16, 1e14, 1), + omega=2*pi*1e9 * 2.99792458e8 / wavelength, omega_p = p[1], gamma_p = p[2], epsilon_inf = p[3], ...){ - cel <- 2.99792458e8 - if(is.null(omega)) - omega <- 2*pi * cel / wavelength - data.frame(wavelength=wavelength *1e6, - epsilon = epsilon_inf - omega_p^2 / (omega^2 + (0+1i) * omega * gamma_p)) - + + if(missing(wavelength)) + wavelength <- 2*pi*1e9 * 2.99792458e8 / omega + + data.frame(wavelength=wavelength, + epsilon = epsilon_inf - omega_p^2 / (omega^2 + (0+1i) * omega * gamma_p)) + } + ##' Objective function for the Drude model ##' ##' Used to fit a Drude model to a material -##' @title fitFDrude +##' @title fit_drude ##' @param p parameters vector (3) -##' @param material data.frame with wavelength in microns and complex epsilon -##' @param ... passed to Drude +##' @param material data.frame with wavelength in nm and complex epsilon +##' @param ... passed to drude ##' @return sum of squares ##' @author Baptiste Auguie ##' @export -fitDrude <- function(p, material, ...){ - - res <- drude(material$wavelength*1e-9, omega_p=p[1], gamma_p=p[2], epsilon_inf=p[3], ...) - - sos.real <- sum((Re(res$epsilon) - Re(material$epsilon))^2) / sum(Re(material$epsilon)^2) - sos.imag <- sum((Im(res$epsilon) - Im(material$epsilon))^2) / sum(Im(material$epsilon)^2) +fit_drude <- function(p, material, ...){ + + res <- drude(material[['wavelength']], p, ...) + + sos.real <- sum((Re(res[['epsilon']]) - Re(material[['epsilon']]))^2) / + sum(Re(material[['epsilon']])^2) + sos.imag <- sum((Im(res[['epsilon']]) - Im(material[['epsilon']]))^2) / + sum(Im(material[['epsilon']])^2) sos.real + sos.imag } diff --git a/demo/AuJC.r b/demo/AuJC.r index 49bd4d8..2c40bd4 100644 --- a/demo/AuJC.r +++ b/demo/AuJC.r @@ -6,9 +6,9 @@ data(AuJC) AuJC$set_span(300, 800) raw <- dielectric2plot(AuJC$raw()) -silver <- AuJC$predict(n=300, all.knots=TRUE) +gold <- AuJC$predict(n=300, all.knots=TRUE) -d <- dielectric2plot(silver) +d <- dielectric2plot(gold) ggplot(d, aes(wavelength, value)) + geom_path() + facet_grid(variable~., scales="free") + diff --git a/man/drude.Rd b/man/drude.Rd index bec3442..9fd9625 100644 --- a/man/drude.Rd +++ b/man/drude.Rd @@ -2,17 +2,18 @@ \alias{drude} \title{drude} \usage{ - drude(wavelength, omega = NULL, p = c(1e+16, 1e+14, 1), + drude(wavelength = 633, p = c(1e+16, 1e+14, 1), + omega = 2 * pi * 1e+09 * 299792458/wavelength, omega_p = p[1], gamma_p = p[2], epsilon_inf = p[3], ...) } \arguments{ - \item{wavelength}{wavelength in m} - - \item{omega}{angular frequency in rad/s} + \item{wavelength}{wavelength in nm} \item{p}{vector of 3 parameters} + \item{omega}{angular frequency in rad/s} + \item{omega_p}{plasma frequency in rad/s} \item{gamma_p}{damping constant, in rad/s} @@ -22,8 +23,8 @@ \item{...}{not used} } \value{ - a data.frame with wavelength in microns and complex - dielectric function + a data.frame with wavelength in nm and complex dielectric + function } \description{ Drude model for the dielectric function of good (governed diff --git a/man/fitDrude.Rd b/man/fit_drude.Rd similarity index 59% rename from man/fitDrude.Rd rename to man/fit_drude.Rd index 13c6e89..e412f1b 100644 --- a/man/fitDrude.Rd +++ b/man/fit_drude.Rd @@ -1,16 +1,16 @@ -\name{fitDrude} -\alias{fitDrude} -\title{fitFDrude} +\name{fit_drude} +\alias{fit_drude} +\title{fit_drude} \usage{ - fitDrude(p, material, ...) + fit_drude(p, material, ...) } \arguments{ \item{p}{parameters vector (3)} - \item{material}{data.frame with wavelength in microns and + \item{material}{data.frame with wavelength in nm and complex epsilon} - \item{...}{passed to Drude} + \item{...}{passed to drude} } \value{ sum of squares