@@ -893,6 +893,11 @@ Namespace Runtime.Internal.Invokes
893
893
''' a POSIXct or POSIXlt or Date object; or an S4 object containing such
894
894
''' an object.
895
895
''' </param>
896
+ ''' <param name="each">
897
+ ''' non-negative integer. Each element of x is repeated each times. Other
898
+ ''' inputs will be coerced to an integer or double vector and the first
899
+ ''' element taken. Treated as 1 if NA or invalid.
900
+ ''' </param>
896
901
''' <param name="times">an integer-valued vector giving the (non-negative)
897
902
''' number of times to repeat each element if of length length(x), or to
898
903
''' repeat the whole vector if of length 1. Negative or NA values are an
@@ -902,15 +907,24 @@ Namespace Runtime.Internal.Invokes
902
907
<ExportAPI( "rep" )>
903
908
Public Function rep(<RRawVectorArgument>
904
909
x As Object ,
905
- times As Integer ,
910
+ Optional times As Integer ? = Nothing ,
911
+ Optional [each] As Integer ? = Nothing ,
906
912
Optional env As Environment = Nothing ) As Object
907
913
908
914
Dim out As New List( Of Object )
909
- Dim vx = REnv.asVector( Of Object )(x)
915
+ Dim vx = REnv.asVector( Of Object )(x).AsObjectEnumerator.ToArray
910
916
911
- For i As Integer = 1 To times
912
- out .AddRange(vx.AsObjectEnumerator)
913
- Next
917
+ If Not times Is Nothing Then
918
+ For i As Integer = 1 To times
919
+ Call out .AddRange(vx)
920
+ Next
921
+ ElseIf Not [each] Is Nothing Then
922
+ For Each item As Object In vx
923
+ Call out .AddRange(Repeats(item, times:=[each]))
924
+ Next
925
+ Else
926
+ Return Internal.debug.stop( "the repeats `times` or `each` element repeats times parameter must be specific!" , env)
927
+ End If
914
928
915
929
Return REnv.TryCastGenericArray( out .ToArray, env)
916
930
End Function
0 commit comments