Thursday 29 October 2015

Error in readRDS(file) : error reading from the connection

I met this error when I was installing the package "stringr". It is one of the dependencies if you want to install "ggplot2" package. I have this problem probably because my computer was interrupted when I was installing "ggplot2" package. But that's just a guess.

Right after the error, it prompts : "TRY removing /usr/local/lib/R/site-library/00LOCK-stringi/". So I just sudo went to that directory and rm -rf 00LOCK-stringi.

I solved the problem this way. But there are a popular ref online:
        http://stackoverflow.com/questions/6473831/readrdsfile-in-r

Try it if my solution doesn't work for you,

Wednesday 28 October 2015

Deal with Missing Data NA in R

Firstly, Yes, there is no " " on NA.

I wrote something like
                   if(mat[i,j] == "NA"){...}

Please don't laugh at me R users...

I got my answer from the following post:
 http://stackoverflow.com/questions/27018471/r-missing-value-where-true-false-needed

comments = c("no","yes",NA)
for (l in 1:length(comments)) {
    if (!is.na(comments[l])) print(comments[l])
}
[1] "no"
[1] "yes"
So the function is.na is the way to do the judgement. And yes use NA directly, no need to quote.

Sunday 25 October 2015

R problem of installing packages: package ‘xxxx’ is not available (for R version 3.2.2) and unable to access index for repository xxxx

I met this problem after re-installed the Ubuntu. I've got to set up the whole programming environment again...  :-{{

--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://cran.utstat.utoronto.ca/src/contrib
Warning message:
package ‘xxxx’ is not available (for R version 3.2.2) 

Checked something online. The following two helped...

http://stackoverflow.com/questions/25721884/how-should-i-deal-with-package-xxx-is-not-available-for-r-version-x-y-z-wa
http://stackoverflow.com/questions/25599943/unable-to-install-packages-in-latest-version-of-rstudio-and-r-version-3-1-1

Basically, just change to another mirror...I changed to one in US, didn't work either... Then Canada(BC), WORKed!!!!

Wired...but you can try the same cuz there might be many problems to the unavailability of a university server, which is usually the case for R mirrors...

Happy coding!

Friday 23 October 2015

VIM color scheme

With "syntax on" command in configuration file "~/.vimrc", the color scheme is really unacceptable for a programmer...

There are many beautiful alternatives. Some commonly used color scheme conf files can be find in Ubuntu directary: "/usr/share/vim/vim7x/colors/" such as desert.vim and morning.vim.

We only need to, in ~/.vimrc, add:
                  colo desert 
                  syntax on

...much better now!

But if you would like to use other color conf downloaded from somewhere else, you have to put the "xxxx.vim" file under the above directary so that vi could locate it automatically.

Hope it helps!

Wednesday 21 October 2015

Unbreakable Linux, Windows and Me: Ubuntu Builder - Installation on Ubuntu 12.04LTS

Unbreakable Linux, Windows and Me: Ubuntu Builder - Installation on Ubuntu 12.04LTS: Ubuntu Builder is a very handy and powerful tool in building a custom Ubuntu linux distro. The following steps are taken for me to succes...

Installing .deb Packages on Ubuntu and Remove it

Sometimes it is more direct to install softwares on Ubuntu using .deb packages like in Windows using setup.exe. Here are some how-to commands.

(1) Installing:
                    sudo dpkg -i xxxxxxxxxxxx.deb

(2) Find out the list of all installed packages:
                    dpkg --list
                    dpkg --list | grep -i keywords

(3) Uninstalling:
With the pack name found using the commands above, we can remove the install.
                   sudo dpkg --remove xxxxxxxx


Continuing and please comment to add more...

WiFi Certificate File Install

  Some WiFi connections require a special certificate in Ubuntu, for example: ca-bundle.crt. And here is the way to install this kind of certs in Ubuntu.

1. copy the cert file to directory: /etc/ssl/certs/
    This is the place in Ubuntu to put the cert file and in other Linux distributions it might be a little different.

2. check the permissions on the cert file.








 Sometimes the original file is with the permission as the following when it has just been downloaded:

-rw------- 1 root root 660107 Oct 21 06:43 ca-bundle.crt


However, the cert file cannot been seen for users when selecting the cert file in filling up the WiFi information. So we need to change it to:

                      -rw-r--r-- 1 root root 660107 Oct 21 06:43 ca-bundle.crt

by command:
                      chmod 644 cert-cert

It means that "I can change it and everyone else can read it".

Now back to the WiFi security table and try to find the cert file, it can be seen.

Hope it helps and happy ubunt'n!

Friday 16 October 2015

vi getting multiple “Sorry, the command is not available in this version…”

Just re-installed Ubuntu, but I am getting the following error codes when launching vi...I am using the configuration from:
    http://jsdelfino.blogspot.ca/2010/11/my-vi-configuration-file.html

Error detected while processing /home/boris/.vimrc:
line   30:
E518: Unknown option: autochdir
line   39:
E319: Sorry, the command is not available in this version: syntax on
line   43:
E319: Sorry, the command is not available in this version: filetype indent on
line   64:
E319: Sorry, the command is not available in this version: function! RESTORE_CURSOR()
line   68:
E319: Sorry, the command is not available in this version: endfunction
line   69:
E319: Sorry, the command is not available in this version: autocmd BufReadPost * call RESTORE_CURSOR()
Press ENTER or type command to continue


Soved by using suggestions from this bbs:

Try from within vim ...
:version
and if your get ...
Small version without GUI.
You are missing package vim-gui-common. It is probably also advisable to install vim-runtime. Commands to install:
sudo apt-get install vim-gui-common
sudo apt-get install vim-runtime

Another cause might be that alternatives is pointing to the wrong one:
update-alternatives --display vim
to show what is used and ...
update-alternatives --config vim
to change to another vim. It could be that /usr/bin/vim.gnome is used and you need /usr/bin/vim

########################################################
It worked for me right after I installed vim-gui-common:
sudo apt-get install vim-gui-common


Hope this helps!

It's because your R is too old

I just want to install ggplot2 for R. But it says I don't have reshape2. Then I tried to install reshape2 but it says
" plyr package for R not available for R version 3.0.2"
I thought this is because the R version is too new. Somebody said and I tried download the plyr package and install. FINALLY I GET:
"ERROR: this R is version 3.0.2, package 'plyr' requires R >= 3.1.0"
So, My R version is too old!!!!

I searched a lot. Only the following worked.
       http://askubuntu.com/questions/218708/installing-latest-version-of-r-base
       http://stackoverflow.com/questions/16093331/how-to-install-r-version-3
=======================================================================
This is an old post and I wrote it when it was impossible to install R with simple (it was installing old 2.15 version):
sudo apt-get install r-base-core
Right now you do not need to do all written below and can simply use the abovementioned command. At the time of updating it will give you 3.1 version.
Here is previous post
Uninstall old R
sudo apt-get remove r-base-core
Open sources.list
sudo nano /etc/apt/sources.list    
and add deb to it
deb http://cran.rstudio.com/bin/linux/ubuntu precise/
precise is your ubuntu name (may be different)
"precise" is 12.04. My ubuntu is 14.04. It should be "trusty"
Add key to sign CRAN packages
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
Add specific PPA to the system
sudo add-apt-repository ppa:marutter/rdev
sudo apt-get update
sudo apt-get upgrade
installing
sudo apt-get install r-base
From R to check version
version
should give you
R version 3.2.2 (2015-08-14)
Hope people will find this helpful


Install Dropbox in Ubuntu

  Dropbox is my working directory but it doesn't work when it is just installed on Ubuntu. I did it in Software Center and it seemed to be installed. When I tried to launch it, it requires the password for super user, and then nothing happened.

I tried the following commands and it works.
          sudo rm -rf /var/lib/dropbox/.dropbox-dist
          dropbox start -i
  It can be seen that the Dropbox starts to downloading now. That is probably the actual installation and that's why the password is required before.


######################################################################

If still does not work for you...try to remove the Dropbox and re-install it again.

           sudo apt-get remove nautilus-dropbox

But there may be problems like:

  "dpkg status database is locked by another process"

Try
            sudo dpkg --configure -a
but not necessary it does the job...it just finishes the unfinished work...anyway it worked for me. Some even say dpkg should never be manually setup. I think it might be easier and safer to just reboot.

Now we could re-install the Dropbox from the .deb package.

            sudo dpkg -i dropbox_2015.02.12_amd64.deb 

Hope it works for you. If not, please comment to share the problems or solutions. Thanks in advance.


Thursday 15 October 2015

Installing chrome gives an error: “dependency is not satisfiable”

Once ubuntu is installed, there are a few routines needed.
http://howtoubuntu.org/things-to-do-after-installing-ubuntu-14-04-trusty-tahr#partners

When trying to install Chrome in Software Center, there might be error showing "dependency is not satisfieable"...

I solved the problem by:
sudo apt-get update && sudo apt-get install -f

This is from:
http://askubuntu.com/questions/46645/installing-chrome-gives-an-error-dependency-is-not-satisfiable

Sunday 11 October 2015

Python Data Structure -- defaultdict()

When using the original Python data structure -- dict(), there will be exception for KeyError if the key doesn't exist when accessing by d[key]. But with difaultdict(), only with a default factory function, it will be used as the default value of the key if the key does not exist. 
# -*- coding: utf-8 -*-
from collections import defaultdict

members = [
    # Age, name
    ['male', 'John'],
    ['male', 'Jack'],
    ['female', 'Lily'],
    ['male', 'Pony'],
    ['female', 'Lucy'],
]

result = defaultdict(list)
for sex, name in members:
    result[sex].append(name)

print result

# Result:
defaultdict(<type 'list'>, {'male': ['John', 'Jack', 'Pony'], 'female': ['Lily', 'Lucy']})

Friday 9 October 2015

Ludovico Einaudi - Nuvole Bianche (Alexander Flemming)

  My piano, my old friend, has just been shipped to our new home. I would like to share this vedio to express my happiness that could not be described by words. There are many many great music piecies I would like to play during the past...7 or 8 years, but this one came to my mind first, alone with all the memories.


  I would like to start this new page "music" to record my music memories because it was, is, and yet to be the most loyal friend in my life. Some memory pieces are beyond words and they can only be remembered by music.