<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/qualtrics-1-0-now-available-from-cran/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.jasperginn.nl/qualtrics-blog/"> Jasper Ginn's blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="https://www.qualtrics.com/about/">Qualtrics</a> allows users to collect online data through surveys. My R package <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/qualtRics/index.html">qualtRics</a> contains convenience functions to pull survey results straight into R using the Qualtrics API instead of having to download survey results manually.</p>
<p>Currently, the package contains three functions:</p>
<ol>
<li><strong>getSurveys()</strong> fetches a list of all surveys that you own or have access to from Qualtrics.</li>
<li><strong>getSurvey()</strong> downloads a survey from Qualtrics and loads it into R.</li>
<li><strong>readSurvey()</strong> allows you to read CSV files you download manually from Qualtrics.</li>
</ol>
<p>Getting started with the package is straightforward. Note that your institution must support API access and that it must be enabled for your account. Whoever manages your Qualtrics account can help you with this. Refer to the <a target="_blank" rel="nofollow" href="https://api.qualtrics.com/docs/authentication">Qualtrics documentation</a> to find your API token.</p>
<h2>Examples</h2>
<p>Register your Qualtrics API key. You need to do this once every R session:</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>qualtRics</span><span>)</span>
<span>registerApiKey</span><span>(</span><span>API.TOKEN</span> <span>=</span> <span>&quot;&lt;yourapitoken>&quot;</span><span>)</span></code></pre>
</figure>
<p>Get a data frame of all surveys to which you have access:</p>
<figure>
<pre><code data-lang="r"><span>surveys</span> <span>&lt;-</span> <span>getSurveys</span><span>(</span><span>root_url</span><span>=</span><span>&quot;https://leidenuniv.eu.qualtrics.com&quot;</span><span>)</span> <span>#</span> <span>URL</span> <span>is</span> <span>for</span> <span>my</span> <span>own</span> <span>institution</span></code></pre>
</figure>
<p>Export a survey and load it into R:</p>
<figure>
<pre><code data-lang="r"><span>mysurvey</span> <span>&lt;-</span> <span>getSurvey</span><span>(</span><span>surveyID</span> <span>=</span> <span>surveys</span><span>$</span><span>id</span><span>[</span><span>6</span><span>],</span>
                      <span>root_url</span> <span>=</span> <span>&quot;https://leidenuniv.eu.qualtrics.com&quot;</span><span>,</span>
                      <span>verbose</span> <span>=</span> <span>TRUE</span><span>)</span></code></pre>
</figure>
<p>You can add a from/to date to only retrieve responses between those dates:</p>
<figure>
<pre><code data-lang="r"><span>surv</span> <span>&lt;-</span> <span>getSurvey</span><span>(</span><span>survs</span><span>$</span><span>id</span><span>[</span><span>4</span><span>],</span>
                  <span>root_url</span> <span>=</span> <span>&quot;https://leidenuniv.eu.qualtrics.com&quot;</span><span>,</span>
                  <span>startDate</span> <span>=</span> <span>&quot;2016-09-18&quot;</span><span>,</span>
                  <span>endDate</span> <span>=</span> <span>&quot;2016-10-01&quot;</span><span>,</span>
                  <span>useLabels</span> <span>=</span> <span>FALSE</span><span>,</span>
                  <span>verbose</span> <span>=</span> <span>TRUE</span><span>)</span></code></pre>
</figure>
<p>You may also reference a response ID. <code>getSurvey</code> will then download all responses that were submitted after that response:</p>
<figure>
<pre><code data-lang="r"><span>surv</span> <span>&lt;-</span> <span>getSurvey</span><span>(</span><span>survs</span><span>$</span><span>id</span><span>[</span><span>4</span><span>],</span>
                  <span>root_url</span> <span>=</span> <span>&quot;https://leidenuniv.eu.qualtrics.com&quot;</span><span>,</span>
                  <span>lastResponseId</span> <span>=</span> <span>&quot;R_3mmovCIeMllvsER&quot;</span><span>,</span>
                  <span>useLabels</span> <span>=</span> <span>FALSE</span><span>,</span>
                  <span>verbose</span> <span>=</span> <span>TRUE</span><span>)</span></code></pre>
</figure>
<p>You can store the results in a specific location if you like:</p>
<figure>
<pre><code data-lang="r"><span>mysurvey</span> <span>&lt;-</span> <span>getSurvey</span><span>(</span><span>surveyID</span> <span>=</span> <span>surveys</span><span>$</span><span>id</span><span>[</span><span>6</span><span>],</span>
                      <span>save_dir</span> <span>=</span> <span>&quot;/users/jasper/desktop/&quot;</span><span>,</span>
                      <span>root_url</span> <span>=</span> <span>&quot;https://leidenuniv.eu.qualtrics.com&quot;</span><span>,</span>
                      <span>verbose</span> <span>=</span> <span>TRUE</span><span>)</span></code></pre>
</figure>
<p>Note that surveys that are stored in this way will be saved as an <a target="_blank" rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/readRDS.html">RDS</a> file rather than e.g. a CSV. Reading an RDS file is as straightforward as this:</p>
<figure>
<pre><code data-lang="r"><span>mysurvey</span> <span>&lt;-</span> <span>readRDS</span><span>(</span><span>file</span> <span>=</span> <span>&quot;/users/jasper/desktop/mysurvey.rds&quot;</span><span>)</span></code></pre>
</figure>
<p>You can read a survey that you downloaded manually using <code>readSurvey</code>:</p>
<figure>
<pre><code data-lang="r"><span>mysurvey</span> <span>&lt;-</span> <span>readSurvey</span><span>(</span><span>&quot;/users/jasper/desktop/mysurvey.csv&quot;</span><span>)</span></code></pre>
</figure>
<p>To avoid special characters (mainly periods) in header names, <code>readSurvey</code> uses question labels as the header names. The question belonging to that label is then added using the <a target="_blank" rel="nofollow" href="https://cran.r-project.org/package=sjmisc">sjmisc</a> package. Qualtrics gives names to these labels automatically, but you can easily change them.</p>
<p><img alt="" src="https://i0.wp.com/www.jasperginn.nl/assets/images/blog/qualtrics-1-available/qualtricsdf.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>If you have any questions or feature requests, please leave them <a target="_blank" rel="nofollow" href="https://github.com/JasperHG90/qualtRics/issues">here</a>.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.jasperginn.nl/qualtrics-blog/"> Jasper Ginn's blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/rloKO3TebQU"></a></div>