conroylau / lpinfer

lpinfer: An R Package for Inference in Linear Programs
GNU General Public License v3.0
3 stars 5 forks source link

Packages are not loaded automatically #1

Closed a-torgovitsky closed 4 years ago

a-torgovitsky commented 4 years ago

The example code should work

func_full_info <- function(df){
  beta = NULL
  y_list = sort(unique(df[,"Y"]))
  n = dim(df)[1]
  yn = length(y_list)
  for (i in 1:yn){
    beta_i = sum((df[,"Y"] == y_list[i]) * (df[,"D"] == 1))/n
    beta = c(beta,c(beta_i))
  }
  beta = as.matrix(beta)
  return(beta)
}

func_two_moment <- function(df){
  beta = matrix(c(0,0), nrow = 2)
  n = dim(df)[1]
  beta[1] = sum(df[,"Y"] * df[,"D"])/n
  beta[2] = sum(df[,"D"])/n
  return(beta)
}

N = dim(sampledata)[1]
J1 = length(unique(sampledata[,"Y"]))
yp = seq(0,1,1/(J1-1))

A_obs_twom = matrix(c(rep(0,J1), yp, rep(0,J1), rep(1, J1)), nrow = 2,
                byrow = TRUE)
A_target = matrix(c(yp, yp), nrow = 1)
tau = sqrt(log(N)/N)

dkqs_cone(df = sampledata,
          A_obs = A_obs_twom,
          A_tgt = A_target,
          func_obs = func_two_moment,
          beta_tgt = 0.375,
          bs_seed = 1,
          bs_num = 100,
          p_sig = 2,
          tau_input = tau,
          solver = "gurobi",
          cores = 1,
          progress = TRUE)

Instead I get

Error in detectCores() : could not find function "detectCores"

If I load the parallel package and try again, I get

Error in gurobi(model, params) : could not find function "gurobi"

So, it seems like packages are not being loaded correctly

conroylau commented 4 years ago

Done! I have added back the :: operator to the functions that require other packages.

a-torgovitsky commented 4 years ago

Seems solved.

But is there a way to better determine whether the user has the correct dependencies? For example, when I first tried to run, I got this

Error in { : task 1 failed - "there is no package called ‘Momocs’"

Presumably this is for something you added (maybe the progress bar?) and installing the package resolved it. But it could be mysterious to an unsuspecting end user.

How does Hadley Wickham suggest dealing with dependencies?

conroylau commented 4 years ago

I figure out that I missed Momocs in the description file yesterday. Does it help in importing dependencies? Thanks!

a-torgovitsky commented 4 years ago

I think that is the right approach. I already went and added Momocs, so I'm not sure how to check this.

conroylau commented 4 years ago

I tried to uninstall Momocs and then install linearprog to test. It works well on my side.

a-torgovitsky commented 4 years ago

Ok good, let's consider this resolved then.