How to create R Package using RStudio?

Part A: Create the package

1. Click File –> New Project…

image

2. Under “New Project” Dialog, Click “New Dirctory

image

 

3. Click “R Package

image

 

4. Profide a “Pakage name

5. Add your files which you want to be packaged.

6. May specify a path where you want this package to be created.

image

7. Click “Create Project

Have a look at this area of RStudio. May do any manipulations, like additing package dependencies.

image

Now, click menu Build –> “Build and Reload

image

You can see it is building:

image

Test your library. The sample R file which I used had only one function called TestFunction()

image

8. Next, you can package it. Click Build –> “Build Binary Package

image

You can go to the folder spcified initially to see the ZIP file created.

image

Part B: Install the package

1. Choose “Install from:”Package Archieve File

2. Choose the “Package archive” by clicking “Browse…” button

3. Click “Install

image

Ta-da…

image

Happy R Packaging!

 

Change missing values in Data Frame to NA in R

 

In the news: Get a Microsoft Professional Degree in Data Science

Home: https://academy.microsoft.com/en-US/professional-degree/data-science/

Microsoft consulted Data Scientists and the companies that employ them to identify the requisite core skills. We then developed a curriculum to teach these functional and technical skills, combining highly rated online courses with hands-on labs, concluding in a final capstone project. Graduates earn a Microsoft Professional Degree in Data Science—a digitally sharable, résumé-worthy credential.

More details here: https://blogs.technet.microsoft.com/justmeetingsnoactualwork/2016/07/14/microsoft-professional-degree-in-data-science/

 

Hello World in Windows 10 IoT Core on Raspberry Pi

Yeah, I know it’s a bit late but I hope still someone will find this useful. Here goes a “Hello World” experiment which displays a “Hello World” and programmatically blinking the LED, which is the activity LED built-in available in the Raspberry Pi Model B Board.

[This post has been in my drafts folder for a long time due to some technical glitches. So please forgive any outdated content]

Here goes the device which I have used for experimenting –> Raspberry Pi2 (which is the latest available at the time of this article)

image_thumb1

Here are the steps I did to kick start.

Hardware Configuration

  1. Raspberry Pi 2 Model B
  2. 5V Power Adapter
  3. USB Keyboard
  4. USB Mouse
  5. WiFi Dongle
  6. TV which supports HDMI & HDMI Cable
  7. SD Card with Windows 10 IoT core for Raspberry Pi pre-loaded

Software Configuration

  1. Visual Studio 2015 Community Edition (with latest updates)

Hello World Sample

STEP 1 – Start with project template

Start with a Blank Universal Windows App. So that you can test your initial program in your laptop/PC itself – i.e., before you deploy it in Raspberry Pi you can have a sneak peek.

image_thumb3

STEP 2 – Action

I have these functionalities:

  1. Display a “Hello, World!” message when you execute the application
  2. Display a message “Hello, Windows IoT Core” when you click a button
  3. A button to “Exit” the application
  4. Switch ON the GREEN LED on the Raspberry Pi board up on clicking “LED ON” button
  5. Switch OFF the GREEN LED off the Raspberry Pi board up on clicking “LED OFF” button

My MainPage.xaml looks like this:

{code goes here}

Code behind – MainPage.xaml.cs looks like this:

STEP 3 – Execute the program in Raspberry Pi

Make sure you have connected to your WiFi from Raspberry Pi. Here in this example, I am demonstrating how to connect to it from Visual Studio to execute the app.

First, Make sure you have “ARM” processor type selected instead or x86 or x64.

image_thumb5

Select “Remote Machine”.

Most probably your Raspberry Pi wil be auto-detected so you just have to select it. Otherwise, provide the IP address which is shown in the Raspberry Pi screen in the field.

image_thumb7

image_thumb11

STEP 5 – RUN

Run the solution / Press F5. You will soon see the app up and running in Raspberry Pi screen. Now test the functionality.

image_thumb12

Reference:

  1. Sample – https://ms-iot.github.io/content/en-US/win10/samples/HelloWorld.htm
  2. Pin Mappings – https://ms-iot.github.io/content/en-US/win10/samples/PinMappingsRPi2.htm
  3. LED operation sample – https://ms-iot.github.io/content/en-US/win10/samples/RGBLED.htm
 

read.csv on R thorws error line “1 appears to contain embedded nulls”

If your read.csv (in openxls) fails by throwing this warning message:

Warning messages:

1: In read.table(file = file, header = header, sep = sep, quote = quote, :

line 1 appears to contain embedded nulls

First thing you might want to try is to check the encoding, or simply trial and error by adding fileEncoding = “utf-16”.

Sample:

require(openxlsx)

df = read.csv("sample.txt", header=TRUE, sep = "|",fileEncoding = "utf-16")

 

.NET Core – Kick-start with “Hello World” in Linux/CentOS

I am considering version CentOS 7.1 in this example. You can read more details installation of .NET Core on various platforms here.
image_thumb6
I am using puTTY, a remote connection tool to connect to my CentOS VM.

Install and configure SDK

Step 1: Install Dependencies libunwind and libicu

If you are interested to know what are libunwind and libicu, please use google. Otherwise please just keep in mind that these libraries are required for the proper functioning of “dotnet” command.
Command: sudo yum install libunwind
image_thumb18
Command: sudo yum install libicu
image_thumb16

Step 2. Download the dotnet.tar.gz file

Command: curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131
image_thumb8

Step 3. Create folder /opt/dotnet

Command: sudo mkdir -p /opt/dotnet
image_thumb10

Step 4. Extract dotnet.tar.gz to newly created folder /opt/dotnet

Command: sudo tar zxf dotnet.tar.gz -C /opt/dotnet
image_thumb12

Create and Test “Hello World” program

Step 1: Create project folder

Create a folder and change the current folder to the newly created one. This is mainly to make sure we do not make unnecessary mess in the root or somewhere else.
Command: mkdir MyNETCoreTest
Command: cd MyNETCoreTest/
image_thumb14

Step 2: Create basic project environment

Apply command “dotnet new”. Since the command is not included in path, you might need to use the full path “/opt/dotnet/dotnet”.
image_thumb27

Check the folder (command: ls) to see if two files are created:

  1. program.cs – the project file. You may check the file contents. You can see a basic “Hello World” program with a Main() method. You can edit the file if wish. I have edited and added a new line.
  2. project.json – project file

image_thumb31
image_thumb33

Step 3: Restore Dependencies

Apply the command “dotnet restore”. This command will restore any necessary packages for the project. You can also see a new file “project.lock.json” also created.
image_thumb37

Step 4: Compile and Execute the program

Finally apply the command “dotnet run”. This command will compile the project – if this project is new, or if any files are modified. Then this will execute the program.

Happy Programming!

 

.NET Core – Kick-start with “Hello World” using Visual Studio

First, make sure you have (at the time of writing this article) below prerequisites already:

  1. Visual Studio 2015 Update 3
  2. .NET Core 1.0 for Visual Studio

I will not be explaining what is happening behind the screens or about the architecture whereabouts since this article is intended to be a kick start-with-the-technology article. I will be demonstrating a .NET Core console based application using Visual Studio 2015.
If everything is ready, let us start! 

Step 1: Create Project

On Visual Studio, create a new project via File → New → Project → Templates → Visual C# → .NET Core, then select the template “Console Application (.NET Core)
You will have to select the .NET framework version 4.5 or above to see the .NET Core specific templates. I will go with .NET Framework 4.6.1 for this example.
image

Click Ok, and you may wait for sometime to finish installing the packages.

Step 2: Display “Hello World”

Write your “Hello World” program. Here is mine:
image

Step 3: Execute the Program

Hit F5 or Run the program and confirm there are no errors.
Ok, mine is success:
image

Step 4: Publish the Project

Right click on the project in Solution Explorer then choose Publish…
image

  1. If this is your first time publishing, you will be asked to choose a publish target.
  2. Type a profile name and click OK.

image
Next, you can either click on “Next >” and modify connection or other settings or directly click “Publish

Step 5: Execute the Published application

Take command-line and navigate to your published folder. My folder looks like this:
image

Apply the command:
> dotnet <filename.dll>
image
Happy Programming!

 

.NET Core – Kick-start with “Hello World” using command line

This example demonstrates the creation of a .NET Core console application and execute it. Whereabouts of what is happening behind the screen and architecture will be discussed in upcoming articles.
Download .NET Core which is the prerequisite for this example should be present in your system. You can download it from here – https://www.microsoft.com/net/core

Step 1: Create a folder

Create a folder so that all your project files will be saved in one place.
image

Step 2: Initialize a basic .NET project

Use the command “dotnet new” to create a basic project.
image
You can see in the folder that two files are created.

  1. Program.cs – A “hello world” console application program. Check the source by opening in notepad or another editor. You can find the Main() method, which is the starting point of a console application in it.
  2. project.json – the project file

image
You can modify Program.cs if wish to experiment. I have added one more line in my example:
image

Step 3: Restore the dependencies

Apply the command “dotnet run” so that it will restore any project dependencies. Will be discussed in detail later.
image
You can see an additional file generated which is project.lock.json.
image

Step 4: Compile and Run the project

Finally, apply the command “dotnet run”. This command will compile the project, then executes it.
image

Note that, if it is a new .cs file, or if there are any modifications then you can see the compilation output in the console. Else it will skip the compile phase.

Happy Programming!

 

K-MUG Machine Learning Day @ Orion India–Personal Review

It was just one week back we announced this special event as the speaker will not be available for a some time after this week so we had to organize this event today (9/July/2016). Despite the fact that it was a short notice and is mostly a non-technical topic, and unexpected morning rains, I was personally expecting a small crowd when compared to our regular K-MUG events but surprisingly we had 25+ audience attended from various companies – Orion, Envestnet, UST Global,  TCS, Tranzmeo, Pinnpark, Wowmakers, Identitymine, Suyati, Entri, Profoundis, etc. to name few. Came to know from the kind of questions asked by audience, and pep talks at networking break – it is found that most of the people were somehow working on Data Analytics topics. This clearly shows where our industry trends are heading to.
WP_20160709_10_17_41_Pro
It was at the venue of MobConf last month, Praseed Pai promised to me to take a K-MUG session on Practical Machine Learning. I was always enthusiastic about Data Science and I also decided that time itself to take a session on Microsoft Azure Machine Learning. Thankfully everything went fine, as usual Orion India Systems agreed to sponsor and organize the event by providing venue (a 60 seat training hall), refreshments and volunteers.
WP_20160709_10_17_47_Pro
Dr. Arun Marar, Project Head for Data Science at ORION kick started the event on time by giving a short talk on the theme.
Praseed Pai made our day by starting from basics of statistics to advanced topics like Decision Trees and Apriori Algorithm. He explained everything using real life examples so that even a novice in the field can easily follow. We ended the program by 1:15PM and agreed to organize a Hackton soon.
Below are the slides I prepared for my Microsoft Azure Machine Learning session:

Here is the social media and mail flyer I designed for the event:

k-mug-July2016