Category Archives: Computers & Internet

My experience doing R trainings at work

Recently, the office decided to set up a small team to manage its social media presence. Because I had somewhat encouraged the development, I was asked to work with them, at least as a facilitator.

Somewhere down the line, I suggested to some on the team that they should consider carrying out analysis of the social media data, at least beyond the metrics that were already available on most of those sites.

I quickly put together a very rudimentary, but useful, Shiny app, (not without some inspiration from this guy) just to demonstrate a bit of what was possible, and they were eager for me to train them in the use of R. I will share more about the app sometime later.

Application that plots social media data

Screenshot of the Shiny app developed for the team

My aim was (and still is) to get them to a point where they could carry out basic analyses on their own and grow from there. I tried to keep the material as basic and non-intimidating as possible – some of the students admitted to a morbid fear of statistics and I didn’t want to scare them off with anything too tough.

I consider myself a beginner still, so this experience really broadened my own understanding of the language. And I had a lot of fun doing it.

Well, I put together some slides on the training sessions and felt I should share them and hopefully get some feedback. Here they are:

  1. Introduction to R Programming
  2. R Data Structures – starting them off on vectors
  3. R Data Structures (Pt. II) – diving into the basics of data frames
  4. R Data Structures (Pt. III) – examining ways of working with matrices
  5. R Data Structures (Pt. IV) – lists (and lists)

The good thing is that some friends and colleagues (outside the office) have told me that, in the coming year, they would like me to train them as well in the use of R.

It’s only an opportunity for me to, yet, learn the more.

Leave a comment

Filed under Computers & Internet

Advantages and Disadvantages of Using IDE [sic]

This is a good blog. I use IDEs, but my take on them is this: It makes a lot of sense for learners to start with manual before moving on to automatic, because the day you’re forced to drive manual, you may find yourself unable to do so.

Expert Wannabe

IDEs are simply programs to write programs. They are generally editing environments with tools
to help programmers write code quickly and efficiently. As an example, we can create PHP-driven
web applications using a combination of Eclipse and PHPEclipse. Core features typically include:

Code completion or code insight: The ability of an IDE to know a language’s
keywords and function names is crucial. The IDE may use this knowledge to do such
things as highlight typographic errors, suggest a list of available functions based on the
appropriate situation, or offer a function’s definition from the official documentation.

Resource management: When creating applications, languages often rely on
certain resources, like library or header files, to be at specific locations. IDEs
should be able to manage these resources. An IDE should be aware of any required
resources so that errors can be spotted at the development stage and not…

View original post 485 more words

Leave a comment

Filed under Computers & Internet

Why you should use the Command Line (a lot…)

My office colleague, “R”, is always on my case: “Ha! I’m always amazed to see you using your command line!” Well, remarks like this, kinda make me feel, geeky, but trust me, I’m no nerd – just some curious cat. It may make one look like they have special powers, but I’m just blessed that the first time I started using (or rather, fooling around) with computers, it was at the command line.

It never did much with it, but that start spared me from the irrational trepidation that many people have towards the console. The only DOS commands I knew back then were CD, DIR, TREE and ROBOCOPY – of which I only used the first three. So, I wasn’t really a user. A few years down the line, atrocious internet connections forced me to do ipconfiging and pinging. But that was it. I’m not a Special One.

I use the command line interface (CLI) nowadays for one simple reason: I’m lazy. Maybe I became lazy since I started doing a lot more programming. Nowadays I work principally from Windows Powershell, which is both a CLI and a scripting environment. It can’t get better than this. But here’s why:

    1. It saves me tons of time: After setting up my Powershell profile, whenever I want to read my Bible, I just type in bible. When I want to log onto my WiFi, I pass the instruction smile, and when I’m done I tell my machine to smileoff. How long did it take me to write the script that enables me to do this? Just a few minutes. How much time is it saving me? Cumulatively, hours!

# Alias: smile/smileoff. Command for controlling my personal Wi-Fi
function Connect-Smile
{
    (netsh wlan connect name='Smile@Maverick')
}
New-Alias -Name smile -Value Connect-Smile

# ----------------------------------------#

function Disconnect-Smile
{
    (netsh wlan disconnect)
}
New-Alias -Name smileoff -Value Disconnect-Smile


  1. I have a lot more control over my computer: As one begins to use the command line more often, one gathers more and more experience on its features and the different possibilities. I know feel much more in control when I’m using the computer and I can customise it a lot more, so that it actually is MY computer. As I pick up one or two scripts (or scripting skills) from the internet and apply them to my system, I can make it bend a lot more to my whims and caprices, and also selectively shut out prying eyes.
  2. I gain more expressivity: I read this blog on this issue and I agree with the author – since I started using the command line, almost exclusively, when interacting with the operating system, the mindless mouse clicking has turned into an actual semblance between me and the computer. For good measure, I included a greeting message in my Profile, so whenever I fire up the program, I get this greeting. Are these the beginnings of AI for me (á la Mark)?

Powershell startup with personalised greeting.

  1. I have less stress after upgrades: I remember the jump I had to make from Windows XP/7 and Windows 8. The difference was so clear and the learning curve quite steep. I recall having to make the same leap from Windows 2000 to XP. Why, oh why, Microsoft??? I upgraded to Windows 10 a few months ago, but guess what? I never had to bother about the new interface. I can count on one hand the number of times I have used the Start Menu. When I first saw it I was like “What the heck?! I will operate from my blue screen, thank you very much.” On a serious note, if you can learn to carry out your most mundane tasks and launch your commonly used programs from the command line, you will save yourself hours or even days and weeks of trying to figure out how to use your PC’s GUI after major operating system upgrades because the CLI stays basically the same. This works across platforms to (in a way); the other day a friend asked me to do something on her Mac and being a Mac-ignoramus, I opened the shell, BASH, and worked from there. She was just staring at me with utter amazement!
  2. I can run many programs and utilities in the same window: I discovered this one only recently and I’m exploring it. Just like I mentioned about ipconfig earlier, I found out that I could run Git and R right there in the CLI. So, when I want to just do a quick commit, I run gitcmd, which I pre-configured in my Powershell Profile to run git-cmd.exe. Alternatively, I could have pointed the Git directory to $PATH (for more information on how to do this in Windows, read this article).

This post is getting too long, sorry. There are other benefits you can discover on your own on the internet. All I am saying to those who are so accustomed to clicking-and-pointing: Learn to use command line, especially if you’re a professional or in any kind of technical field. It will save you a lot of hassle once you get the hang of it.

Cheers.

Leave a comment

Filed under Computers & Internet

CS50: Learning computer science can be pure, unadulterated fun!

I think I’m reasonably educated (I can still do a lot better) and have sat under a number of teachers in my short lifetime. Recently, I decided to make a move into the field of computing – it’s not been that easy but very rewarding.

First, let me state that I have grown to believe that a deeper knowledge of computing is gradually becoming an absolute necessity for any serious professional. The coming of Big Data, AI and IoT have convinced me of this. On a personal level, my interest in all things statistics and data in my work and business have naturally taken me down this path.

Not that I was completely strange to computers. Being the curious cat that I am, I wrote my first computer program (the creation of a sprite) while visiting a friend in my days in medical school. After compulsory national service, my colleagues couldn’t understand why I was walking around with a book on calculus – and I didn’t understand it either. Perhaps it was the cock in me that was crowing

But, let me get to the point of this post. Recently I’ve been enduring a lot of really boring instructors when learning about R and C++ (I read somewhere that programmers are really poor teachers, as this is evident when you try to decipher the standard documentation that comes with these programming languages). So, the first time I came across Harvard’s CS50, I just skipped it. (I had taken one course in Harvard 2 years ago and it was really lousy.)

When I decided to look at the course again, I was simply blown away. Indeed, CS50’s reputation as the most popular computer science course is well deserved. It is simply a fantastic experience of pure fun and at the same time challenging enough to get one going in learning about computing basics.

The Professor, David Malan, and the rest of the staff are super brilliant and so, so good at teaching computer skills to both neophytes and hackers. I have never seen it done so well!

The good thing is that it’s not about one particular programming language, but about principles and combs quite effectively through low-level C paradigms, to higher level coding such as web programming (HTML, CSS, PHP) and SQL.

So, to sum it all up:

  • Computing is very important and is going to be more important in the years to come.
  • An easy, fun and stimulating introduction to computing (as well as refresher for more experienced programmers) is available with CS50.

You can set aside the 12 weeks-plus to take the course online on edX. The ongoing course will be ending December 31, 2016, but I’m pretty sure there will  be another opportunity soon. To get a whiff of what’s in the course, take a look at this video!

If you’re thinking of learning about programming, go for it. You will never regret it.

4 Comments

Filed under Computers & Internet

Get to use Facebook data via R

I’ve been building a Shiny app for work in the office. I was made to head a team that does some sort of web monitoring and we’ve decided to use R for some of the analyses. Before I attempt to detail some of the work done in the past couple of months or so, I will briefly share my attempt to access Facebook data just yesterday. The package to use is called Rfacebook, co-developed and maintained by Pablo Barbera.

First, open R. If you don’t have the package installed, run the code

install.packages("Rfacebook")

and then load it using library(Rfacebook)

To use the package, you need to first get a Facebook API access token – a temporary one that works for just 2 hours or one that you can use repeatedly for different sessions. To get the former, visit https://developers.facebook.com/tools/explorer/; for a permanent token, register an app with https://developers.facebook.com/ using your Facebook account, if you have one. The instructions in the documentation are actually crisp enough to guide you through the process; to access it, run help(fboauth).

I also found this blog, where the process is given in detail. Knowing Facebook’s penchant for changing things, don’t be surprised if there are slight modifications to the guidance you find here or elsewhere!

There are 3 things you want out of this – 1. App Version 2. App ID and 3. App Secret.

Now that you have your main details ready, you may want to store your token in your working directory so that you can call it up whenever you want to collect data through the API. The Rfacebook documentation proposed something like this

app_id <- 123XXXXXXX12345
app_secret <- ABDEFXXXXXXXXXXXXXXXXXXXX9876545
token <- fboauth(app_id, app_secret)
save(token, "my_token")
# Call up token later using load("my_token")

 

This last line with save() didn’t work for me and I can’t tell why. I even tried saving it as .RData file to no avail. This is what I did

saveRDS(token, "my_token.rds")

To use it, I would then use something like

token <- readRDS("my_token.rds)

 

Having done all, I could use different functions in the package. My only disappointment was that the main function that I had looked forward to using, searchFacebook(), has been deprecated for the current API version (at the time of writing this blog, v2.8) and Facebook had already retired the version (v1.0) for which this was possible.

So, I find the package only marginally useful for now, but will experiment a little and share if I find something interesting.

2 Comments

Filed under Computers & Internet