Open clarkfitzg opened 6 years ago
We can use this to actually try running it:
n = 10
dyncut = function(x, ...) c(-Inf, 0, Inf)
local_pems = data.frame(station = rep(1:3, length.out = n)
, flow2 = rnorm(n), occupancy2 = rnorm(n))
npbin(local_pems)
If you know the return type of mean, sd, length and cut() - which we do - this seems entirely knowable if you also know the types of the columns of x. In other words, you don't need a "full-blown type inference system". It will help, but you can get a long way pretty quickly.
For this particular use case it seems that we would have to:
breaks
and columns of x
breaks[-1]
sapply(x, f)
returns a vector of the same type as the return type of f
Can this package help then?
In the code below I would like to infer that
npbin()
produces a dataframe with columns:c("station", "right_end_occ", "mean_flow", "sd_flow", "number_observed")
and column typesc("integer", "numeric", "numeric", "numeric", "integer")
.I can get the column names by analyzing the call to
data.frame()
that produces the output. But to get the column classes in general I think I need a full blown type inference system.Below you can assume that the argument
x
will be a data frame with columns known ahead of time, anddyncut()
outputs a numeric vector.Here's the context for this code: https://github.com/clarkfitzg/pems_fd/blob/master/nonparametric/base_r.R