PageRenderTime 87ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/TutorialSimpleData.r

http://r2clr.codeplex.com
R | 52 lines | 18 code | 11 blank | 23 comment | 0 complexity | 786e9b850f17543e622421a031a94fbe MD5 | raw file
  1. #### https://r2clr.codeplex.com/
  2. rclrRoot = 'f:/codeplex/r2clr' # set this to your own location
  3. library(rClr)
  4. clrInit()
  5. # Use the couple of following lines if you want to run basic unit tests prior to undertaking the tutorial.
  6. # library(testthat)
  7. # test_package('rClr')
  8. # clrLoadAssembly(dllFilename=file.path( rclrRoot, 'doc/DataConversionSample/bin/Release/DataConversionSample.dll'))
  9. # or
  10. clrLoadAssembly(dllFilename=file.path( rclrRoot, 'doc/DataConversionSample/bin/Debug/DataConversionSample.dll'))
  11. clrGetLoadedAssemblies()
  12. # [1] "mscorlib" "ClrFacade" "System.Core" "System"
  13. # [5] "RDotNet" "RDotNet.NativeLibrary" "DataConversionSample"
  14. typename = clrGetTypesInAssembly('DataConversionSample')
  15. typename = "rClr.Samples.DataConversionSample,DataConversionSample"
  16. obj = clrNew(typename)
  17. obj
  18. clrReflect(obj)
  19. # $Methods
  20. # [1] "DateTimeToString" "Equals" "GetDate" "GetHashCode" "GetOneDimArray"
  21. # [6] "GetOneDimStringArray" "GetRectArray" "GetType" "ToString"
  22. # $Fields
  23. # character(0)
  24. # $Properties
  25. # character(0)
  26. clrGetMemberSignature(obj, "GetDate")
  27. # [1] "Static, Method: DateTime GetDate, String"
  28. str(clrCallStatic(typename, "GetDate", '2001-02-03'))
  29. # Date[1:1], format: "2001-02-03"
  30. str(clrCallStatic(typename, "DateTimeToString", as.Date('2001-02-03')))
  31. # chr "3/02/2001 12:00:00 AM"
  32. str(clrCallStatic(typename, "GetOneDimStringArray", as.integer(5)))
  33. # chr [1:5] "0" "1" "2" "3" "4"
  34. str(clrCallStatic(typename, "GetOneDimArray", as.integer(5)))
  35. # num [1:5] 0 1.1 2.2 3.3 4.4
  36. str(clrCallStatic(typename, "GetRectArray", as.integer(3), as.integer(5)))
  37. # num [1:3, 1:5] 0 1.1 2.2 0.22 1.32 2.42 0.44 1.54 2.64 0.66 ...
  38. # What a .NET object looks like
  39. clrCallStatic('System.Environment', 'get_Version')
  40. # Dictionaries are not yet converted to R lists, by default.
  41. clrCallStatic('System.Environment', 'GetEnvironmentVariables')