[R] Please help me in Converting this from C# to R

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sun Sep 14 09:04:46 CEST 2008


2008/9/14 rajivv <rajiv_das at rediffmail.com>:
>
> Random r = new Random();
>                DirectedGraph<SimpleNode> graph = GetGraph();
>                decimal B = 0.1m;
>                decimal D = 0.05m;
 [ deletia ]
>                        if (P[i] < 0)
>                            P[i] = 0;
>                    }
>                }
>
>            }

 If you convert it into English first, then more people will be able
to help. It's much easier to convert English to any programming
language than from programming language A to programming language B.
Given that this code must have derived from a specification written in
a human language (such as English) just supply us with that. Sometimes
you don't need the original spec if the code is well-commented. But
this code is null-commented.

 At a guess, it seems to get a graph from out of nowhere
(graph=GetGraph()) and then do 100 iterations of some calculation
based on the graph adjacency. This should not be too difficult to
convert to R, but with any conversion problem there are always hidden
traps to beware of. Here's one in your code:

 You have:

  for (int i = 7; i <= 10; ++i)

 in one loop, and:

  for (int t = 0; t < 100; ++t)

 Now, much as C style loop specifications are concise and elegant,
they can cause confusion. The subtle differences here (using < instead
of <=, and the 'preincrement' ++i) confuse me as to what values the
loop variable takes in the loop.

 The way to get by all these issues in any conversion problem is to
have a good set of test cases. You run the test cases in language A
and get a set of answers. You then run the test cases using the
converted code in language B and if you don't get the same answers
then the conversion has failed.

 If you can describe what the code does, add some meaningful comments,
and produce a set of sample data test cases and results then perhaps
you'll get more help than just pasting the code in and asking nicely
(you did say 'please', which is more than some people do on this
list!).

Barry



More information about the R-help mailing list