I have the R code for Fisher's exact test, however, I it's a bit too much and I am getting bogged down trying to read through the code.

My objective is to calculate the test for a 2x2 table, but I am a bit confused as to where to begin...

I understand that I should first write a hypergeometic function to calculate the initial p value of the given table, but I am confused how to create the marginal frequency tables...

Thank you

ps. apophenia won't install :-(

I cannot speak to the quality of this site or their code but if you go to
http://ligarto.org/rdiaz/Software/Software.html, the Pomelo package seems to have what you are looking for (get the "Download the source code for the statistical tests" package).

That Apophenia library seems to have a lot of dependencies if you don't have the Gnu Scientific Library or SQLite it probably barfs on you.