0

I'm trying to work through some of the examples in this article around table generations using expss - https://cran.r-project.org/web/packages/expss/vignettes/tables-with-labels.html - however, I am consistently getting the error could not find function "setalloccol" using the most basic crosstab functions of cro and fre with two variables:

> cro(df$var1, df$var2)
Error in setalloccol(ans) : could not find function "setalloccol"

I'm using R Studio 1.2.1335 and I've re-installed the packages dplyr, data.table, tidyr and expss itself, but I still seem to get this error with all these libraries running. I've googled the exact error I'm coming up with and there is absolutely zilch on this, so appreciate any help...

TimL
  • 211
  • 2
  • 11
  • You've definitely not just installed the libraries, but also loaded them? It's hard to help you debug without having any of your code. I'm not familiar with expss; here is `setalloccol` supposed to come from? – camille Jan 27 '20 at 14:44
  • Yep I've installed and loaded the libraries. Setalloccol is a data.table command I believe, but not entirely sure what it's being used for here. – TimL Jan 27 '20 at 15:03
  • have you tried with alloc.col instead? – Carbo Jan 27 '20 at 15:05
  • it's not an explicit command from my end - I am running a simple command with `cro` or `fre` like you would with the `table` command, eg `cro(df$var1, df$var2)` but it comes back with the error in the post title... very confusing as i'm not sure anything is deprecated - the article I'm reading is from only a couple if months ago! – TimL Jan 27 '20 at 15:08
  • Folks are just going to be stuck guessing unless you can [edit] to include the code where the error comes up – camille Jan 27 '20 at 15:27
  • seems like u need to reinstall data.table and expss see https://github.com/gdemin/expss/issues/42 – chinsoon12 Jan 28 '20 at 00:28

4 Answers4

2

Try to explicitly export setalloccol from data.table before running your code:

setalloccol = data.table::setalloccol
# further calculations
# cro(df$var1, df$var2)
Gregory Demin
  • 4,596
  • 2
  • 20
  • 20
1

'Setalloccol' is an experimental command in data.table used to allocate memory by reference to assure something more stable than a shallow copy is allocated by ':='. 'Expss' looks like a monster library. I won't load it now and track down your error. But since 'setalloccol' is an experimental command, you should find the 'expss' developers and file a defect. There is, however, already a whole gnarly open bug report on this exact issue here: https://github.com/gdemin/expss/issues/42. The developer of data.table ("Matt Dowle") has comment in that bug report. In practice setalloccol works like this:

help(setalloccol)

data.table::truelength(HMR)
[1] 1035
options(datatable.verbose=TRUE)
data.table::setalloccol(HMR,2 * 1035)
data.table::truelength(HMR)
[1] 2081

But it really isn't necessary for most data.table computations. Try to pour over the "expss" code and find why and when they use it. Sorry I am not more helpful.

rferrisx
  • 1,598
  • 2
  • 12
  • 14
1

Thanks to rferrisx for the thread from GitHub. The post from josie-athens from 3rd Nov 19 seems to fix this issue, though I didn't run R from Bash. So my process was:

  1. Uninstall expss and data.table packages: remove.packages(c('expss','data.table'))
  2. Reinstall above packages: install.packages(c('data.table','expss'))

This seems to bypass the error. Not entirely sure why though but hopefully helpful for somebody experiencing the same thing.

TimL
  • 211
  • 2
  • 11
1

For what it's worth, I just ran into the same issue and wanted to give my two cents. This seems to be a matter of the order in which you load the packages, since the "expss" package masks several functions of the "data.table" package and vice versa. Try reversing the loading order. At least that solved the issue for me.

timw
  • 11
  • 1