Coder Social home page Coder Social logo

unitted's People

Contributors

aappling-usgs avatar appling avatar

Stargazers

 avatar

Watchers

 avatar

unitted's Issues

compatibility with testthat

expect_more_than loses the units of one of the two objects. For example:

> expect_more_than(u(1,"ho"),u(2,"ho"))
 Error in unitted_Ops(.Generic, e1, unitted(e2, NA)) : 
  Units mismatch in comparison 'e1 (ho) < e2 ()'

accessors for unitted_tbl_df

this breaks:

> tb <- u(dplyr::tbl_df(data.frame(site_name="nwis_01484680", lat=u(38.6, "degN"), lon=u(-75.1, "degE"))))
> tb
Source: local data frame [1 x 3]

      site_name  lat   lon
U               degN  degE
1 nwis_01484680 38.6 -75.1
> tb$lat
Error in unitbundle(units) : 
  invalid class for units specification - must be data.frame, character, NA, unitbundle, or missing

Units conversion function

Many standard conversions could be made available. I'm envisioning a function that takes the current and desired units and finds the appropriate conversion between them.

`[<-` for unitted_data.frames

Some assignments to new columns work, others don't:

> library(unitted)
> df <- u(data.frame(x=1:3, y=4:6), c('a','b'))
> df$c <- TRUE
> df['d'] <- FALSE
Error in unitted(object, units, ...) : 
  Number of units must equal number of data.frame columns
> df[,'d'] <- FALSE
Error in unitted(object, units, ...) : 
  Number of units must equal number of data.frame columns
> df[['d']] <- TRUE

overview doc

package-unitted.R (or unitted-package.R?) should contain overview of functions the user might want to use, e.g., u, v, get_units, and verify_units

enable new unitted classes

I wanted to let the user create new unitted classes at will, but neither S3 nor S4 classes are unittable with new_unitted_class when unitted is loaded as a package rather than in dev mode. These examples were in @examples section of new_unitted_class, before I took them out and made that function not-exported:

#' ## S4 ##
#' 
#' # "myS4flower": An S4 class to be made unitted
#' setClass("myS4flower", contains="numeric", slots=c(leaves="numeric", petals="numeric", color="character"))
#' 
#' # Define the unitted version of myS4flower
#' new_unitted_class("myS4flower") 
#' 
#' # Try out the new unitted_myS4flower class
#' petunia <- new("unitted_myS4flower", c(frontyard=7, backyard=3, planters=12), leaves=4, petals=5, color="purple", units="stems ft^-2")
#' petunia * u(1/2,"blooming")
#' ## S3 ##
#' 
#' # "quote": An S3 class to be made unitted
#' two_cities <- c("It was the best of times, it was the worst of times, ",
#'                 "it was the age of wisdom, it was the age of foolishness, ",
#'                 "it was the epoch of belief, it was the epoch of incredulity, ",
#'                 "it was the season of Light, it was the season of Darkness, ",
#'                 "it was the spring of hope, it was the winter of despair...")
#' class(two_cities) <- "quote"
#' attr(two_cities, "author") <- "Charles Dickens"
#' print.quote <- function(x) { cat(paste(paste(x, collapse="\n"),"\n   - ",attr(x,"author"))) }
#' print(two_cities)
#' 
#' # Now make it unittable
#' setClass("quote", contains="character", slots=c(author="character"))
#' 
#' # And now make it unitted
#' new_unitted_class("quote", overwrite=TRUE)
#' two_cities_unitted <- new("unitted_quote", 
#'   two_cities, author=attr(two_cities, "author"), units="lines")
#' see_spot_run_unitted <- new("unitted_quote", 
#'   c("Here is Spot.","See Spot run.","Run, Spot, Run!"), author="unknown", units="sentences")
#' print(two_cities_unitted)
#' print(see_spot_run_unitted)
#' sum(!is.na(see_spot_run_unitted))

html vignette

jordan's excellent suggestion: "Possibly turn your vignette into an html vignette? I found the ppt style to be kind of tricky to take in. Laura has a good one for EGRETci if you want to take a look"

unitted_Ops for two data.frames

In this function in arithmetic.R:

setMethod(
  "unitted_Ops", c("ANY","ANY"), ...

a call to udf1 + udf2 breaks with non-numeric argument to binary operator because the code is trying to call the operator (e.g., +) on two lists of unitbundles here:

return(switch(
        .Generic,
        "+"=, "-"=, "*"=, "/"=, "%%"=, "%/%"= { 
          unitted(do.call(.Generic, list(deunitted(e1), deunitted(e2))),
                  do.call(.Generic, list(get_unitbundles(e1), get_unitbundles(e2)))) }, ...

That's not right. There should probably be an mapply in there.

common arithmetic funs, e.g., mean, min, max

mean, sqrt, abs, min, max, ...
?Summary: "max", "min", "range", "prod", "sum", "any", "all"
?log: log, logb, log10, log2, log1p, exp, expm1
?Trig: sin, cos, ...
?mean: weighted.mean, colMeans
?Math: abs, sign, sqrt, ceiling, floor, trunc, cummax, cummin, cumprod, ...
?Math2: round, signif
?Complex: Arg, Conj, Im, Mod, Re

chron compatibility

unitted dfs apparently don't work with chron

cana$dtime<-chron( as.numeric(cana$DateTime)/86400-0.25)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘unitted’ for signature ‘"chron"’

sqrt doesn't get applied to elements of unitted vectors

test_that("Known bug: sqrt doesn't get applied to elements of a unitted vector", {
  miles_vec <- unitted(1:5,"mi")
  -miles_vec

  #sqrt seems not to get applied to elements of a unitted vector
  x <- u(data.frame(a=1:3,b=3:5),c("a","q"))
  expect_equal(v(sqrt(x)), sqrt(v(x)))
})

`[`, `$`, etc. for unitted_tbl_dfs

ugh to all of this:

library(dplyr)
library(unitted)
> tbl <- u(data_frame(a=1:4, b=5:8), c('A','B'))
> tbl
Source: local data frame [4 x 2]

      a     b
U     A     B
  (dbl) (dbl)
1     1     5
2     2     6
3     3     7
4     4     8
> tbl$a
Error in unitbundle(units) : 
  invalid class for units specification - must be data.frame, character, NA, unitbundle, or missing
> tbl['a']
Error in unitted(vx, new_units) : 
  Number of units must equal number of data.frame columns
> tbl[,'a']
Error in unitted(vx, new_units) : 
  Number of units must equal number of data.frame columns

conflicts with tibble

tibble + unitted = not yet harmony.

> library(unitted)
> library(tibble)

Attaching package:tibbleThe following object is masked frompackage:unitted:

    as_data_frame

> x <- tibble(x=1:3, y=2:4)
Found more than one class "tbl_df" in cache; using the first, from namespace 'tibble'
Found more than one class "tbl_df" in cache; using the first, from namespace 'tibble'
Found more than one class "tbl_df" in cache; using the first, from namespace 'tibble'
Found more than one class "tbl_df" in cache; using the first, from namespace 'tibble'
Found more than one class "tbl_df" in cache; using the first, from namespace 'tibble'
Found more than one class "tbl_df" in cache; using the first, from namespace 'tibble'
Found more than one class "tbl_df" in cache; using the first, from namespace 'tibble'
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tibble_1.1    unitted_0.2.5

loaded via a namespace (and not attached):
 [1] lazyeval_0.2.0  magrittr_1.5    R6_2.1.2        assertthat_0.1  plyr_1.8.4      rsconnect_0.4.3
 [7] DBI_0.4-1       tools_3.3.1     dplyr_0.5.0     Rcpp_0.12.5 

Error for plotting unitted data.frame when logging one axis

plot(gpp.disch$disch, gpp.disch$gpp, log='x')
Error in unitted_Ops(.Generic, e1, unitted(e2, NA)) : 
  Units mismatch in comparison 'e1 (ft^3 s^-1) <= e2 ()'

units of disch and gpp are different, yes. But no error for plot(gpp.disch$disch, gpp.disch$gpp, log='')

verify_units breaks on POSIXct

verify_units(u(as.POSIXct('2017-01-19'), ''), '')

gives

Error in verify_units(u(as.POSIXct("2017-01-19"), ""), "") : 
  Unrecognized data type in unitted object

using dplyr-unitted functions within other packages

I tried to do this in another function:

#' @import dplyr
#' @importFrom unitted mutate_.unitted_data.frame
...
x <- function() {
...
  y <- u(data.frame(i=1:4, j="k"), c("ii","jj"))
  site_names <- c("A","B","C")
  y < - mutate(y, h=site_names)
...
}

but that didn't work because the version of mutate that got called was all dplyr, no unitted.

Warning messages:
1: In class(x) <- c("tbl_df", "tbl", "data.frame") :
  Setting class(x) to multiple strings ("tbl_df", "tbl", ...); result will no longer be an S4 object

So then I tried to specify the unitted version

#' @import dplyr
#' @importFrom unitted mutate_.unitted_data.frame
...
x <- function() {
...
  y <- u(data.frame(i=1:4, j="k"), c("ii","jj"))
  site_names <- c("A","B","C")
  y < - mutate_.unitted_data.frame(y, h=site_names)
...
}

but the problem here is that site_names is a local variable, and it doesn't get properly evaluated in mutate_.

Error in unitted(object, units, ...) : 
  error in evaluating the argument 'object' in selecting a method for function 'unitted': Error in unitted(object, units, ...) : binding not found: 'A'

Similarly, if you change the mutate line to this:

  y < - mutate_.unitted_data.frame(y, h="site_names")

you get this:

 Error in unitted(object, units, ...) : 
  error in evaluating the argument 'object' in selecting a method for function 'unitted': Error in unitted(object, units, ...) : binding not found: 'site_names'

We need mutate() without the _, and we need to be able to specify that we want the unitted version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.