Tag Archives: GitHub

Mapping Nigeria’s Geopolitical Zones in R

The other day I got an email from a researcher who is using the naijR package, which, among other things, helps with the drawing of plot maps of Nigeria. He was having trouble drawing maps of the geopolitical zones (GPZ) of the country.

Admittedly, this is an omission from the package, but a deliberate one. I had actually toyed with the idea of baking this feature in, but since the GPZ is not “officially” recognized, I opted for the package to be relatively silent, as only States and Local Government Areas are recognized in the Nigerian Constitution.

Anyway, after a few emails back and forth, I was able to help him resolve the issue. Basically, since the states() function can extract the States by GPZ (via the gpz argument), we can use this little dearie to extract the States of a GPZ and pass it to the region argument of map_ng(). For the Northeast GPZ, this gives us a map that might look like this:

Delineating all the GPZ on a country map is a little trickier and we have to do some functional programming. One approach is to generate a data frame with the contiguous States matched to a factor that represents each GPZ. Then, we draw a choropleth map by passing that data frame to the data argument of map_ng(), while the factor is passed to the x argument. Information for using these arguments can be found in ?map_ng(). In the output below, I chose reddish colouring for the map.

Problem solved. The code for this solution can be found in this GitHub Gist. To get the raw script, follow this link. I think I’m going to have to review the decision on not implementing a native drawing of GPZ maps in naijR.

Leave a comment

Filed under Computers & Internet, Data Scoemce

RQDAassist v.0.3.1

This is to announce a new version of the R package RQDAassist, a package whose goal is to make working with RQDA much easier.

This version principally adds new functionality in the retrieval of codings from a project database. The function takes as arguments the file path to an RQDA project and a string containing a valid SQL query (SQLite flavour). As a default, one does not need to specify the query. The function does this internally to fetch data from relevant tables in the .rqda file. Thus, for a project MyProject.rqda, one can simply call

retrieve_codingtable("path/to/MyProject.rqda")

The default query that is run internally by this function is as follows:

SELECT treecode.cid AS cid, codecat.name AS codecat
FROM treecode, codecat
WHERE treecode.catid=codecat.catid AND codecat.status=1;

The user is at liberty to form their own queries; a reference for the database tables is in the RQDA package and the documentation for this function (accessed with ?retrieve_codingtable) provides a quick link to that help page. For example, if we want to just collect the filenames of the transcripts used in an analysis, we can use a different query. Note that the data are returned invisibly, to prevent cluttering of the console, so it’s better to bind it to a variable.

qry <- "SELECT DISTINCT name FROM source WHERE status=1;"
tbl <- retrieve_codingtable("path/to/MyProject.rqda", qry)
tbl

We can easily try this out using material from the excellent RQDA workshop conducted by Lindsey Varner and team. We can download the sample project they used right inside R:

url <- "http://comm.eval.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=101e221b-297e-4468-bfc9-8deccb4adf8c&forceDialog=0"
project <- "MyProject.rqda"
download.file(url, project, mode = 'wb')

If we check the working directory with list.files, we should see the project there. Next, using our package’s function, we can get a data frame with information on codings.

> df <- retrieve_codingtable(project)
> str(df)
Classes ‘codingTable’ and 'data.frame':	39 obs. of  9 variables:
 $ rowid       : int  1 2 3 4 6 9 10 12 13 14 ...
 $ cid         : int  1 1 2 1 2 4 4 1 4 3 ...
 $ fid         : int  2 2 2 2 2 2 3 4 4 4 ...
 $ codename    : chr  "Improved Time Management" "Improved Time Management" "Improved Organization" "Improved Time Management" ...
 $ filename    : chr  "AEA2012 - Post-Program Interview1" "AEA2012 - Post-Program Interview1" "AEA2012 - Post-Program Interview1" "AEA2012 - Post-Program Interview1" ...
 $ index1      : num  1314 1398 1688 1087 2920 ...
 $ index2      : num  1397 1687 1765 1175 2964 ...
 $ CodingLength: num  83 289 77 88 44 296 120 150 210 116 ...
 $ codecat     : chr  "Positive Outcomes" "Positive Outcomes" "Positive Outcomes" "Positive Outcomes" ...

We see that we now created a data frame with 9 columns, with interesting data in them. Note particularly the variables codename, filename, and codecat. Let us now carry out the other query we gave as an example – to get the filenames of all the transcripts in the project:

> qry <- "SELECT DISTINCT name FROM source WHERE status=1;"
> tbl <- retrieve_codingtable(project, qry)
> tbl
                                name
1  AEA2012 - Post-Program Interview1
2  AEA2012 - Post-Program Interview2
3  AEA2012 - Post-Program Focus Group
4  AEA2012 - Pre-Program Focus Group

This project contains only 4 active files from which all the codings are derived!

A practical point

This function is useful for developing qualitative codebooks, and particularly when coding is carried out inductively and as has been demonstrated, can be extended to other uses, depending on the kind of data that are retrieved.

Installation

The easiest way to install the package is from an R session with

# install.packages("remotes")
remotes::install_github("BroVic/RQDAassist")

This is a source package, and to build it on Wiindows, Rtools needs to have been properly installed.

Leave a comment

Filed under Computers & Internet, Data Scoemce

An R package to help with RQDA

A few weeks aga, I published a package on GitHub, which I called RQDAassist. The package was inspired by a script I wrote to help RQDA users, myself included, to install the package after it was archived on CRAN when R 4.0 arrived on the scene. So, when RQDAassist was first published, that was its only real functionality.

Today, I am releasing a minor update (v. 0.2.0) that has a few functions added. It can now convert transcripts written in Word into plain text files – a desired format for RQDA projects – and it can prepare those test files into objects that can be read, in bulk, into an RQDA database. Another thing I personally needed for my work was the ability to seaarch qualitative codes using R scripts rather than the graphics user interface; so I wrote a search function, which currently works for active RQDA projects.

This package has so far been tested on Windows 10 (x64) but it should work fine on other major platforms (any subequent update will include the relevant tests for Linux and Mac OS).

There are no plans to take this package to CRAN and indeed there should be no need to do so once RQDA installation from that repository is fully restored. But I find the prospect of additional helper functions to be quite useful in my work and hope others do too. I hope to see these functionalities expand over time.

You are welcome to check out this project at the GitHub repository or try it out using the instructions in the README.

Leave a comment

Filed under Computers & Internet

Help with installing RQDA

RQDA user interface
The RQDA User Interface

[Update – 25 Nov 2020]: In the last 3-4 days, there has been significant activity on the RQDA GitHub repository, specifically addressing the needed updates to the package. So, it’s expected that very soon, the package will once again be available for installation via the regular channels.

RQDA is software for computer-aided qualitative data analysis (CAQDAS) and is specifically tailored for use with the R programming language and statistical computing environment. Last year I was privileged to use RQDA in carrying out the data analysis for an assessment involving 4 Nigerian States. It’s a great package, and very user-friendly. I was able to engage a team of non-programmers and after a 2-hour training, they were good to go, giving me great results.

A few months ago, somebody raised an alarm on the package’s GitHub repository. RQDA was gone!

GitHub Issue #38: Package was archived on CRAN
You need to see the comments that followed after!

What followed was a long discussion – many researchers were adversely affected by this development. Fortunately, my project was properly isolated using package management powered by renv and I really had no problems at all. But others were not so fortunate, and some didn’t even know how to start solving the problem. I participated somewhat on the thread to see how I could help out a few people.

You see, what had happened was that some of the dependencies of RQDA on CRAN, the Comprehensive R Archive Network, had been upgraded and the maintainer of RQDA, Prof. Ronggi Huang of Fudan University, China, was yet to upgrade the project accordingly. With the upgrading of R to version 4.0, these packages were all archived on CRAN and could not be installed the regular way i.e. with install.package(). On a good day, installing RQDA already presents some challenges, because of the graphical user interface (GUI) libraries it uses. Now it was impossible, except for advanced R users.

One of the developers on the thread took it upon himself to work on a fork of the project and came up with a good solution. And it worked. RQDA could be downloaded and installed with little or no pain. However, when colleagues asked whether he was going to commit to maintaining the fork or even pushing to CRAN, he declined, and rightly so. Instructions for using his branch can be found here.

Given this scenario, I decided that it would be good to also develop a solution based on the last available CRAN version, even though it was archived. I therefore came up with an R script that can be used both in the shell and within an R session. With this solution, RQDA can be successfully installed from CRAN on the current version of R (v4.0.2), I tried to provide informative messages to guide would-be users in carrying out the required steps – in some cases, there might be a need to stop the script and carry out an intermediary step at the R console. This script has been uploaded here as a GitHub Gist.

To use this script, follow these steps:

  1. Download the script and save it to disk–its name is gwdg-arch.R. Note the location where it is saved.
  2. Navigate to the directory/folder where the file in the shell or in an R session.
  3. Run the script:
    • If in the shell, use Rscript gwdg-arch.R.
    • If in the R console, use source("gwdg-arch.R")
  4. If RGtk2 was successfully installed by the script, it will terminate. You should now go to the R console and run library(RGtk2); this will bring up a dialog, asking you to install Gtk+. Accept it.
  5. After installing Gtk+, run the script again to download and install the other packages, including RQDA.
  6. If the above steps fail, perhaps your system is lacking some extraneous dependency. Run the script in the shell, only this time add the flag --verbose. This will print out more messages to help identify the possible cause of the problem.

Feel free to give me a shout.

1 Comment

Filed under Computers & Internet