R – Error: package or namespace load failed for “rJava”

Background

Users opens up a ticket regarding issues running an R Script on a new machine.

Error Message

Image

errorloadingpackage.rjava.20190109.0251pm

Textual


Error: package or namespace load failed for "rJava":
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: fun(libname, pkgname)
  error: No CurrentVersion entry in Software/JavaSoft registry!
  Try re-installing Java and make sure R and Java have matching architectures.

Explanation

Unable to load rJava module.

Troubleshooting

java

Is java Installed?

Outline

  1. OS Platform
    • OS :- Windows
      • GUI
        • Control Panel
      • Console
        • java.exe

OS Platform

MS Windows
GUI – Control Panel

Accessed Control Panel, but no Java Applet.controlpanel.20190109.0355pm

Console – java.exe

Syntax


java -version

Syntax – Check specifically for 64-bit


java -d64 -version

Output

Image

java.-d64.20190109.0407pm

Textual


>java -d64 -version
Unrecognized option: -d64
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

 

Remediation

java

Download Java Runtime Environment ( JRE)

Download 64-bit Java JRE from here :-

Java SE Runtime Environment 8 Downloads
Link

java.artifact.20190109.0412pm

Install Java

Install the download artifacts

Validate Java

Validate Java ( x64 )

Syntax

java -d64 -version

Output
Output – Before – Image

java.-d64.DoesNotSupportA64bitJVM.20190109.0419PM.PNG

Output – Before – Textual

Error : This Java instance does not support a 64-bit JVM.
Please install the desired version.

Output – After

java.-d64.Supports64bitJVM.20190109.0420PM.PNG

 

R

Access System

In R, issue call to system.

The call is to validate that the R Script can access the system and invoke the java executable.

System calls

System Call – java
Syntax

system('java -version")

Output
system.java.-version.20190109.0424pm

 

 

 

 

 

R – Error Message – “… appears to contain embedded nulls”

Background

Ran into a little error message in R.

 

Error Message

Error Snippet

Here is the error message:

line # appears to contain embedded nulls

Error Body


 bibleBooks = read.table("BibleBook.txt", header=TRUE)
Warning messages:
1: In read.table("BibleBook.txt", header = TRUE) :
  line 1 <span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>appears to contain embedded nulls<span id="mce_SELREST_end" style="overflow:hidden;line-height:0;"></span>
2: In read.table("BibleBook.txt", header = TRUE) :
  line 2 appears to contain embedded nulls
3: In read.table("BibleBook.txt", header = TRUE) :
  line 3 appears to contain embedded nulls
4: In read.table("BibleBook.txt", header = TRUE) :
  line 4 appears to contain embedded nulls
5: In read.table("BibleBook.txt", header = TRUE) :
  line 5 appears to contain embedded nulls
6: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
  embedded null(s) found in input

Troubleshooting

Look at the file being imported and saw that yes it has delimiters, line-breaks for each row, but did not have column separators.

Remediation

Outline

  1. Decide on a column delimiter
    • In our case most of our columns are numeric
    • We only have one column, book name, and it does not have semi colon in it
    • And, so we are OK having semi-colon (;)
  2. BCP
    • Issued BCP with semi-colon
      • Syntax -t
  3. R
    • read-table
      • Issue read-table and specify sep argument
        • sep
          • In our case sep=”;”

 

Text Files

bibleBookHeader.txt

BookID;BookName;NumberofChapters;NumberofVersesInLastChapter;VerseIDStart;VerseIDEnd;Testament

Command File

ExportData.cmd

setlocal

set "_server=localhost"
set "_fieldTerminator=;"

bcp  "select * from  bible..BibleBook"  queryout  bibleBookRaw.txt -S %_server% -T -t %_fieldTerminator% -c 

copy bibleBookHeader.txt + bibleBookRaw.txt bibleBook.txt

endlocal

R Console

Command


bibleBooks = read.table("BibleBook.txt", sep=";", header=TRUE)

bibleBooks

Console

RConsole_20180620_0707AM

References

  1. Statistical tools for high-throughput data analysis ( STHDA )
    • Reading Data From TXT|CSV Files: R Base Functions
      Link