Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, January 08, 2013

Watch a Random Episode for Any Show on Hulu

Sometimes you just want to watch a random episode of a show on Hulu. Select a show and a link to a random episode will appear; click "Get Random Episode" to get a different random episode.




Tuesday, February 13, 2007

Eclipse EPIC Plugin Syntax Error-Parsing Bug

EPIC is a Perl IDE plugin for the Eclipse platform. It has an unresolved bug where Perl files saved with a syntax error cannot be opened again and Eclipse will produce the following ambiguous error when opened:
Unable to create this part due to an internal error.
Reason for the failure: Argument not valid
For instance, the following code would cause an error due to a missing curly brace and a syntax error with the regular expression:
} elsif($test =~ /)
#Statement
}
If the code is too complex to edit readily using the Open With -> Text Editor option, then copying the code to a new Perl document will highlight the syntax error normally.

Friday, April 21, 2006

Building A Windows Binary R Package

A binary version of an R package can be created by using the following command.
R CMD BUILD --force --binary packagename
This command requires the use of a commandline zip program. This program can be downloaded as part of Cygwin. If Rtools is being used to create the R package then the Cygwin zip program located at C:\cygwin\bin\zip.exe needs to be copied into the Rtools directory.

This type of package is installed using the Packages -> "Install package(s) from local zip files..." in Windows RGui.

Tuesday, March 14, 2006

Install R Packages On Linux Without Changing Permissions For Users

Typically, R installs packages /usr/lib/R/library/; other locations can be added using the R_LIBS environment variable in a Linux environment. If R_LIBS is null, R defaults to /usr/lib/R/library/

To change R_LIBS
export R_LIBS=/somefolder/
To check whether the variable was changed
echo $R_LIBS
Restart R to ensure that the packages in the alternative location are read. Packages installed in this fashion must be the Windows binary version of the package and must be unzipped into the directory. The library() command is used in the normal fashion.
library(somepackage)
This will only work for the current Linux session. To make the change permanent the export R_LIBS command can be placed in .bash_profile.

Sunday, March 05, 2006

Spreadsheet::ParseExcel Warnings

An unresolved bug exists in the Perl module Spreadsheet::ParseExcel version 0.2603, which causes warnings to be displayed
Character in 'c' format wrapped in pack at /usr/lib/perl5/vendor_perl/5.8.6/Spreadsheet/ParseExcel.pm line 1790.
Character in 'c' format wrapped in pack at /usr/lib/perl5/vendor_perl/5.8.6/Spreadsheet/ParseExcel.pm line 1789.
While the warnings do not cause errors in the module output they are irritating when parsing large spreadsheets. A workaround involves changing basic changes to the two lines of code:

Before
substr($sWk, 3, 1) &= pack('c', unpack("c",substr($sWk, 3, 1)) & 0xFC);
substr($lWk, 0, 1) &= pack('c', unpack("c",substr($lWk, 0, 1)) & 0xFC);
After
substr($sWk, 3, 1) &= pack('C', unpack("C",substr($sWk, 3, 1)) & 0xFC);
substr($lWk, 0, 1) &= pack('C', unpack("C",substr($lWk, 0, 1)) & 0xFC);
Essentially, you are changing the lowercase "c" to capital "C", in all instances in the two lines. The error is caused by the module attempting to mask the last two bits of the character by unpacking it to a signed number, masking 0xFC, and then repacking it to a signed number. By changing, the letter the same operation is performed using unsigned integers.

Sunday, December 18, 2005

IE <pre> overflow Attribute Error

Internet Explorer fails to properly render the <pre> tag overflow: auto correctly. A simple hack from this forum post:
/* IE Fixes */
* html body pre {
    width: 95%;
    height: 100%;
    overflow: auto;
}

Friday, December 16, 2005

Creating a R Package in Win XP with Cygwin

The short answer you can't build packages using Cygwin tools and a Windows installation of R. Building a package with R requires certain Unix tools and trying to set the Windows Path environment variable to include cygwin\bin does not work because the programs are not compiled in a way R can use them.
Necessary Tools

The tools you'll need to create the package (these are all required)

  1. The Unix utilities, Rtools, by Brian Ripley and Duncan Murdoch. A batch file later in this article requires the zip file to be placed in C:\Program Files\R\R_VERSION\Rtools
  2. If the package contains C/C++/Fortran code you will need the MinGW GNU compiler set.
  3. ActiveState Perl
  4. The Microsoft html help compiler
  5. A version of TeX (MikTex)
Creating Package Structure
A basic R package requires two files in the top level directory. Throughout this article packagename refers both to the name of the package and the name of the top level folder when used with Rcmd.exe.

DESCRIPTION
NAMESPACE
And two subdirectories
man:     Documentation
R:    R functions
The DESCRIPTION file has the following format:
Package: pkgname
Version: PROGRAMVERSION
Date: DATE
Title: TITLE
Author: Joe Developer , with contributions from A. User .
Maintainer: Joe Developer 
Depends: R (>= R_VERSION)
Description: A short (one paragraph) description of what the package does and why it may be useful.
License: GPL version 2 or newer
URL: http://www.r-project.org, http://www.another.url
The NAMESPACE file contains a list of functions in your package which will be available to the user:
export( function1, function2, ... )
The man folder contains documentation for R objects written in "R documentation" (Rd) format that is similar to LaTeX. The man\packagename.Rd file has the following format:
\name{packagename}
\alias{packagename}
\title{Title}
\description{...}
\usage{function(arg1, arg2, ...)}
\arguments{
\item{arg_i}{arg_i description}
}
\examples{...}
\seealso{...}
\keyword{key}
The R folder contains R code to be included in the package:
function_name=
function(arg) {...}
Setting Up Tools

The following batch script masks a Cygwin installation from R by setting the PATH environment variable to only the directories necessary to build or install an R package. All R CMD commands should be run in the command prompt the following batch file creates.

NOTE: This scripts works even if Cygwin is installed. HOWEVER, you can not have any Cygwin applications running (not even a shell or XEmacs for Cygwin) at the same time you try to run RCMD.
@echo off
rem ###################################################
rem # Usage: RCMDprompt.bat [path]
rem #
rem # This script opens a MS-DOS prompt with a enviroment variables
rem # set such that R can be ran and packages can be build.
rem # If 'path' is given, the working directory will be set accordingly.
rem #
rem # NOTE: This scripts works even if Cygwin is installed.
rem # HOWEVER, you can not have any Cygwin applications
rem # 
running (not even a shell or XEmacs for Cygwin) at the same
rem #
time you try to run RCMD.
rem #
rem # Requires:
rem # To build and install packages two things must be installed, i.e.
rem # exists in the PATH. First, the Rtools compilation [1] by B.
rem # Ripley must exists. The path (R_TOOLS) to it is set below.
rem #
Second, Perl (must not be Cygwin/Perl) must also exists. The
rem #
path to it is set below.
rem #
rem # Reference:
rem # [1] http://www.stats.ox.ac.uk/pub/Rtools/
rem #
rem # Henrik Bengtsson, hb at maths.lth.se, Mar-04
rem # Modified by Augustin Luna, augustin at mail.nih.gov, Dec-05
rem ###################################################

rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem # 1. "Global" environment variables
rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem # Short version of PROGRAMFILES, e.g. 'C:\Progra~1' instead of
rem # 'C:\Program Files\', which contains spaces that are BAD for R
set PROGRAMFILES_SHORT=C:\Progra~1

rem # Directory where user directories are
set USERSDIR=C:\Docume~1

rem # Set the main R directory
set R_ROOT=%PROGRAMFILES_SHORT%\R

rem # Set the R_HOME directory (THIS LOCATION MAY BE DIFFERENT)
set R_HOME=%R_ROOT%\rw2011
rem set R_HOME=%R_ROOT%\rw2011

rem # Set the HOME directory. This is the directory where R looks
rem # for the .Rprofile and .Renviron files. See ?Startup.
set HOME=%USERSDIR%\%USERNAME%
rem # Set TMPDIR to a temporary directory
set TMPDIR=%TEMP%

rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem # 2. Setup the PATH
rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem # Clear the PATH (making the main Cygwin installation
rem # "invisible")
path ;

rem # Set the LaTeX directory (Using default installation parameters)
path C:\texmf\miktex\bin;%PATH%

rem # Set the Microsoft HTML Help Compiler directory
path %PROGRAMFILES%\HTML Help Workshop;%PATH%

rem # Set the Perl directory
path C:\Perl\bin;%PATH%

rem # Set the Rtools\bin directory
rem # (THIS LOCATION MAY BE DIFFERENT)
path %R_HOME%\Rtools\bin;%PATH%

rem # Set the R_HOME directory
path %R_HOME%\bin;%PATH%

rem # Set the WINDOWS directory
path %SystemRoot%;%PATH%

rem # Set the WINDOWS/system32 directory
path %SystemRoot%\system32;%PATH%

rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem # 3. Start the MSDOS prompt in the given directory
rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
rem # Change directory according to argument 1
cd %1%

rem # Start the MSDOS commando prompt
%SystemRoot%\system32\cmd.exe
Modifications from the original RCMDprompt.bat script
Checking Package Documentation

The CHECK parmeter is used to check the documentation of the package for any errors.

Rcmd.exe CHECK packagename
You may see the following error:
* checking packagename-manual.tex ... ERROR
LaTeX errors when creating DVI version.
This typically indicates Rd problems.
Typically, but not always and not in this case. You now need to do the following

  1. Run the MiKTeX options program, choose the TeX formats page, and then for the following programs to use the old engine (latex and pdflatex) do the following:
  2. Click on the Edit button,
  3. Choose "pdfTeX" as the compiler,
  4. Click Apply,
  5. Click Build
After doing this re-run Rcmd.exe CHECK packagename. Most likely you will get a popup titled "Package Installation" attempting to install the following packages:
upquote and lm
Click Change; Select Internet; Choose a Package Repository and click Finish. Click Install. The popup will reappear if you there are any other necessary packages that need to be installed.

Building Package
Rcmd.exe BUILD packagename
Installing Package
Rcmd.exe INSTALL packagename_version.tar.gz
References
Making R Packages Under Windows by Peter Rossi (PDF)
http://cran.r-project.org/doc/manuals/R-exts.html
http://www.murdoch-sutherland.com/Rtools/
https://stat.ethz.ch/pipermail/r-devel/2004-March/029152.html