From asaguiar at spsconsultoria.com  Wed Aug  3 07:28:34 2011
From: asaguiar at spsconsultoria.com (Alexandre Aguiar)
Date: Wed, 3 Aug 2011 02:28:34 -0300
Subject: [Rd] example package for devel newcomers
In-Reply-To: <E2134178-595D-4E43-A2AF-1BE28CE1C81A@r-project.org>
References: <201107311845.50264@spsconsultoria.com>
	<CAB9w6Xw9TCTJ9uW2GE=QaGn0HbO4jf-8gWeA-T5w1-F4DxzftA@mail.gmail.com>
	<E2134178-595D-4E43-A2AF-1BE28CE1C81A@r-project.org>
Message-ID: <201108030228.39854@spsconsultoria.com>

Simon,

Thanx for your feedback.

Em Ter?a 02 Agosto 2011, voc? escreveu:
> .. also note that there is Rserve PHP client (used, e.g., by FastRWeb)
> which works around a lot of the issues you encounter when you try to
> embed R into PHP (initialization cost, lack of thread-safety, no
> workspace separation etc.).

Did not overlook Rserve. Nice piece of software.

The purpose of (to be) Rphp is different. Suppose we have php files 
top.php, right.php, left.php and bottom.php that build the frame around a 
central portion of a website's webpages. This basic scheme is used by 
most web content management systems (WCMS).

In a simple view things will work like:

--------R cgi script pseudocode-----------
# first get data from command line
data <- getcgidata()
html.title <- function(txt) {
   print(paste"<center><h1>",txt,"</h1></center><br><br>",sep="")
}
php("include '/somedir/top.php'") # php needs full path
php("include '/somedir/left.php'")
# perform calculations
RES <- calculations(data)
html.title("Results")
# printout results in the RES R variable
print(RES)
php("include '/somedir/right.php'")
php("include '/somedir/bottom.php'")
-------------------------------------------

The intended result is to have an output fully compliant with the WCMS 
without messing up with WCMS itself. Besides php(), another function is 
implemented to get values from specific php variables, user defined or 
system.

BTW, libphp5.so output is directed to R cgi script output (stdout in cgi) 
that is sent away through the internet connection but could also be 
trapped and saved to a variable for further handling.

---+ pesudocode----------
php("$V1=2")
php("$V2=5;")
php("$V3=4;$V4=4")
php("$VAL=$V1+$V2+$V3-$V4")
calc_val <- php.get("VAL") # or calc_val <- php("echo $VAL")
-------------------------

In the php() function the semicolon statement delimiter can be omitted 
after the last or the only php statement.

The pseudocode operation above is not useful at all. However, any function 
added with php() or declared within php files included or php systemwide 
extensions available (PEAR libraries, for instance) can be called by R 
scripts. Users always get creative and despite my own limited purpose, I 
guess many inventive uses may appear. For instance, Berkeley db, inifiles 
support, time/zone database, support to exif info in jpeg and tiff files, 
some 20 or 30 different hashes, ftp support, JSON, SOAP client  and 
server (this can do amazing things) can all become available to R.

Kindest regards.


-- 


Alexandre

--
Alexandre Santos Aguiar, MD, SCT
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20110803/5058a846/attachment.bin>


[Rd] example package for devel newcomers
Alexandre Aguiar