code: public static boolean isRserveInstalled(String Rcmd) {
          Process p = doInR("is.element(set=installed.packages(lib.loc='" + RserveDaemon.app_dir() + "'),el='Rserve')", Rcmd, "--vanilla --silent", false);
          if (p == null) {
              Log.Err.println("Failed to ask if Rserve is installed");
              return false;
          }
  
          try {
              StringBuffer result = new StringBuffer();
              // we need to fetch the output - some platforms will die if you don't ...
              StreamHog error = new StreamHog(p.getErrorStream(), true);
              StreamHog output = new StreamHog(p.getInputStream(), true);
              error.join();
              output.join();
  
              if (!RserveDaemon.isWindows()) /* on Windows the process will never return, so we cannot wait */ {
                  p.waitFor();
              } else {
                  Thread.sleep(2000);
              }
              result.append(output.getOutput());
              result.append(error.getOutput());
  
              if (result.toString().contains("[1] TRUE")) {
                  Log.Out.println("Rserve is already installed.");
                  return true;
              } else if (result.toString().contains("[1] FALSE")) {
                  Log.Out.println("Rserve is not yet installed.");
                  return false;
              } else {
                  Log.Err.println("Cannot check if Rserve is installed: " + result.toString());
                  return false;
              }
          } catch (InterruptedException e) {
              return false;
          }
      }
docs: R batch to check Rserve is installed
  
  @param Rcmd command necessary to start R
  @return Rserve is already installed