Wednesday, August 3, 2016

Myanmar-Sar in R III: Light, SQLite


There was this large scale data collection and data management scenario for an important nation-wide event. The kind of data to be collected is deceptively simple but the catch is that the sheer size of the operation makes it a formidable undertaking. When the results were in, the scores were found to be not that enviable. Judging from what meager information available on the official websites, those from interested local NGOs, international contractors and NGOs with stakes in this undertaking, my dumb guess is that the responsible parties and the public seemed to have been caught unawares. Well, enough of my obscure remarks. Let's get down to work.

The plan was to have the central database maintained by PostGresSQL with SQLite databases at Township level serving as data collection points and exchanging data with the central system through offline and online data transfers. It was specified that Myanmar-3 font, the standard font for Myanmar Government agencies, will be used for both user interface and database storage. In this context, the idea basically, I guess, is to encode the data transmitted in Myanmar-Sar as well as in other forms in UTF-8 system.

Well, that's quite some interesting topic for small guys to play with, as usual, for fun (and and may be of some use). One possible solution in this context, I guess, is to collect data in the field using a CSEntry application on Android phones and upload the text data files at township data collection point(s) to an SQLite database via R. Then the stored data could be uploaded to PostGresSQL database online or offline. Continuing my explorations with Myanmar-Sar in R, the modest objective of the exercise for this post will be to try to create a simple SQLite database via R and see how it handles Myanmar-Sar.

For this exercise, you need to have RSQLite package installed on your machine and we will still be using the State/Region Pcode data of MINU we have used for the last two posts as the source data. The R script is self-explanatory:


What is remarkable here is that when you upload data with Myanmar-Sar to SQLite database from R, and retrieve it back, and then write the result to a text file, you do not lose the Myanmar-Sar as we can see below:


However, if you were to write the data read into R as SR_MIMU dataframe and try to write it directly into text file:

                 write.csv(SR_MIMU, file = “SR_MIMU_direct.csv”, row.names = FALSE)

you'll get this instead.


To get a text file with correct Myanmar-Sar, you'll need to use writeLines() in the correct way in this situation. We have shown that in our earlier post.


No comments:

Post a Comment