albertosantini / node-rio

Integration with Rserve, a TCP/IP server for R framework
https://github.com/albertosantini/node-conpa
MIT License
176 stars 35 forks source link

Couldn't pass Image tests on Mac (example 5) #7

Closed xhinking closed 11 years ago

xhinking commented 11 years ago

Hi albertosantini,

I have a problem on example 5.After running grunt on master code (on node v0.10.19 and v0.10.7):

$ grunt

Running "jshint:src" (jshint) task
>> 3 files lint free.

Running "vows:all" (vows) task
>>
>> ♢ Basic tests
>>   double number test
>>     ✓ get the double number
>>   double number array test
>>     ✓ get the double number array
>>   string test
>>     ✓ get the string
>>   string array test
>>     ✓ get the string array
>>   utf8 string test
>>     ✓ get the utf8 string
>> ♢ Image tests
>>   first image test
>>     ✗ get image
>>         » expected 2259,
>>      got  9999 (==) // image-test.js:31
>> ✗ Broken » 5 honored ∙ 1 broken (0.560s)
>>
>> vows:all done
Warning: Task "vows:all" failed. Use --force to continue.

Aborted due to warnings.

I have tried tag 0.10.0, test is ok. But I got a blank png from node ex5.js.

Thank you!

albertosantini commented 11 years ago

After cloning the repo and setting export CI=true (just to exclude Rserve instance), execute npm install and then npm test: with node 0.10.19 the tests are ok.

Then I started a Rserve instance (R 3.0.1 - Rserve 1.7.3) from R console: require(Rserve) and Rserve().

I removed the continuous integration flag: export CI=false. I launched again the tests: npm test.

And eventually I executed the image example (after moving to the examples folder): node ex5.js. The image myPlot.png is ok.

I cannot replicate the issue (on Windows 7 64).

Any hint?

albertosantini commented 11 years ago

Firstly you may check R environment:

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252   
[3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C                  
[5] LC_TIME=Italian_Italy.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rserve_1.7-3

loaded via a namespace (and not attached):
[1] tools_3.0.1
> png(filename="temp.png")
> plot(1:10)
> dev.off()
null device 
          1 
> 

A temp.png file is created (2259 bytes) in your default folder containing the plot.

xhinking commented 11 years ago

This is my R environment.

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base  

Yes, I can get temp.png in my R console and node ex1.js is correct. But node ex5.js was still got a blank png: ( I will check my node environment.

albertosantini commented 11 years ago

Did you try to get a few more info with debug flag?

rio.enableDebug(true);

xhinking commented 11 years ago

I've tried enableDebug but couldn't find any clue.

Connected to Rserve
Supported capabilities --------------

Sending command to Rserve
00000000: 0300 0000 ec00 0000 0000 0000 0000 0000  ....l...........
00000010: 04e8 0000 6372 6561 7465 4475 6d6d 7950  .h..createDummyP
00000020: 6c6f 7420 3c2d 2066 756e 6374 696f 6e20  lot.<-.function.
00000030: 2829 207b 0a20 2020 2066 696c 656e 616d  ().{.....filenam
00000040: 6520 3c2d 2074 656d 7066 696c 6528 2270  e.<-.tempfile("p
00000050: 6c6f 7422 2c20 6669 6c65 6578 7420 3d20  lot",.fileext.=.
00000060: 222e 706e 6722 290a 0a20 2020 2070 6e67  ".png")......png
00000070: 2866 696c 656e 616d 6529 0a20 2020 2070  (filename).....p
00000080: 6c6f 7428 313a 3130 290a 2020 2020 6465  lot(1:10).....de
00000090: 762e 6f66 6628 290a 0a20 2020 2069 6d61  v.off()......ima
000000a0: 6765 203c 2d20 7265 6164 4269 6e28 6669  ge.<-.readBin(fi
000000b0: 6c65 6e61 6d65 2c20 2272 6177 222c 2039  lename,."raw",.9
000000c0: 3939 3929 0a20 2020 2075 6e6c 696e 6b28  999).....unlink(
000000d0: 6669 6c65 6e61 6d65 290a 0a20 2020 2069  filename)......i
000000e0: 6d61 6765 0a7d 0a63 7265 6174 6544 756d  mage.}.createDum
000000f0: 6d79 506c 6f74 2829 0001 0101            myPlot()....

Data packet
00000000: 2514 2700 0f27 0000 8950 4e47 0d0a 1a0a  %.'..'...PNG....
00000010: 0000 000d 4948 4452 0000 01e0 0000 01e0  ....IHDR...`...`
00000020: 0806 0000 007d d4be 9500 0004 2469 4343  .....}T>....$iCC
00000030: 5049 4343 2050 726f 6669 6c65 0000 3811  PICC.Profile..8.
00000040: 8555 df6f db54 143e 896f 52a4 163f 2058  .U_o[T.>.oR$.?.X
omit some text...
000026e0: 585b 40fb bbbf fbbb 38f9 e493 6397 5d76  X[@{;?{;8yd.c.]v
000026f0: 89bf fccb bf8c 279f 7c32 468d 1a15 cb97  .?|K?.'.|2F...K.
00002700: 2fdf 4209 ab09 1020 4080 40f3 0504 f016  /_B.+...@.@s..p.
00002710: ac76 de79 e778 e000                      ,v^ygx`.

Type SEXP 37
Response value: �PNG

b{����IS�*�IH{��!&�U��vb'S�\���9�9�;�^�D=_i��U������$�����M�ҳ�Kԫ�N-���.����������N�#�z��щ"O�n}�
omit some text...
�h����ѣG�8�裫f\B��
8n�Ĉ1mڴ�v�m�?�A�r�)�~��FJ�D��' ���t��w����cҤI1|������;w����g[(ah��ނ�o��?~�&[�=��x���7Y�     (D@oA-9�}���7���sϥg���� �EX[@�����8���c�]v���˿�'�|2F�˗/�B  �  @�@���v�y�x�
Disconnected from Rserve
Closed from Rserve
myPlot.png saved in /Users/xhinking/Developer/github/node-rio/examples
albertosantini commented 11 years ago

I see a difference in the first bytes of the packet

Data packet
00000000: 25d8 0800 d308 0000 8950 4e47 0d0a 1a0a  %X..S....PNG....
00000010: 0000 000d 4948 4452 0000 01e0 0000 01e0  ....IHDR...`...`
00000020: 0803 0000 004a 0a4e a700 0000 7250 4c54  .....J.N'...rPLT
00000030: 4500 0000 0000 3a00 0066 003a 3a00 3a66  E.....:..f.::.:f
00000040: 003a 9000 66b6 3a00 003a 003a 3a00 663a  .:..f6:..:.::.f:
00000050: 3a66 3a3a 903a 90db 6600 0066 003a 6600  :f::.:.[f..f.:f.
00000060: 6666 3a00 663a 9066 6666 66b6 ff90 3a00  ff:.f:.ffff6..:.

2514 2700 0f27 0000 (yours) vs. 25d8 0800 d308 0000 (mine). It is not Byte Order Mark (BOM), maybe it is the length of the file. The rest of the eight bytes is the standard PNG signature: 8950 4e47 0d0a 1a0a.

Please check the length of the file created by the following code, executing it in R console:

    filename <- tempfile("plot", fileext = ".png")

    png(filename)
    plot(1:10)
    dev.off()

In my environment the length is 2259.

The script ex5.R reads up 9999 bytes. If the file created on OSX is greater, you should modify the script accordingly. For instance,

image <- readBin(filename, "raw", 77777)

Indeed the image test says it got 9999 bytes. Maybe it is enough to set a greater buffer. :)

albertosantini commented 11 years ago

I tested the creation of a image from R console on a Linux environment and I am quite sure the length of the file is the issue.

On Linux the length of the image file is 4.1Kb. It is below the (maximal) number of records to be read, 9999, for readBin I set in the example.

In Travis environment the test is passed because the image is read from the disk and not created runtime because R framework is not installed. This is the reason in Travis the image test is ok.

Please check the image file length.

> png("trashme.png")
> plot(1:10)
> dev.off()

It should be greater than 9999, as I said in my previous comment.

xhinking commented 11 years ago

It's finally worked!

> png("trashme.png")
> plot(1:10)
> dev.off()

The png file size is 13096. I changed the buffer size 9999 to 77777 and got the correct image through ex5.js.

Thank you albertosantini!