title: R - TableOne -- Error in ModuleStopIfNoVarsLeft : No valid variables
body: <p>I'm trying to use TableOne [<a href="https://cran.r-project.org/web/packages/tableone/tableone.pdf]" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/tableone/tableone.pdf]</a> in R to create a table. The data I'm using looks at patients who have undergone surgery and need a table of their existing medical conditions. I tried with the full dataset (30+ cols), but made a smaller df of just four to try and get this working.</p>
  
  <p>Comorbidities (htn, hl, cv) are coded as TRUE/FALSE; and I have converted them to numeric using: </p>
  
  <pre><code>df$data &lt;- as.numeric(df$data)
  </code></pre>
  
  <p>I have put my code below, and the associated error.</p>
  
  <p>For reference:</p>
  
  <pre><code>tp is the dataframe
  htn/hl/cv are three separate columns, each is True/False within tp
  age is a column of continuous within tp
  </code></pre>
  
  <h3>Convert logical to numeric</h3>
  
  <pre><code>&gt; tp$htn &lt;- as.numeric(tp$htn)
  &gt; tp$hl &lt;- as.numeric(tp$hl)
  &gt; tp$cv &lt;- as.numeric(tp$cv)
  </code></pre>
  
  <h3>Check all numeric</h3>
  
  <pre><code>&gt; str(tp)
  Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   1199 obs. of  4 variables:
   $ htn : num  0 0 0 0 1 0 1 1 1 1 ...
   $ hl  : num  0 0 0 0 0 0 1 0 1 1 ...
   $ cv  : num  0 0 1 0 0 0 0 1 1 1 ...
   $ age : num  81.2 85.5 80.4 69.4 67.3 ...
  </code></pre>
  
  <h3>Create variable list for table</h3>
  
  <pre><code>&gt; listvars &lt;- tp[c("htn", "hl", "cv", "age")]
  </code></pre>
  
  <h3>Create categorical variable list for table</h3>
  
  <pre><code>&gt; catvars &lt;- tp[c("htn", "hl", "cv")]
  </code></pre>
  
  <h3>Create table</h3>
  
  <pre><code>&gt; table1 &lt;- CreateTableOne(vars = listvars, data = tp, factorVars = catvars)
  </code></pre>
  
  <h3>Error is as follows:</h3>
  
  <pre><code>**Error in ModuleStopIfNoVarsLeft(vars) : No valid variables.
  In addition: Warning message:
  In ModuleReturnVarsExist(vars, data) :**
  </code></pre>
  
  <p>I have attempted to fix it, firstly as above by ensuring all the variables are numeric, not just logical. Secondly, cut the dataset to only four columns as above, as I thought perhaps it required using all variables in the dataset. </p>
  
  <p>I'm unsure how to proceed, any help greatly appreciated.</p>