<commit_before>/*
 * SessionTeX.cpp
 *
 * Copyright (C) 2009-11 by RStudio, Inc.
 *
 * This program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include "SessionTeX.hpp"

#include <string>

#include <core/Log.hpp>
#include <core/Error.hpp>
#include <core/FilePath.hpp>
#include <core/FileSerializer.hpp>

#include <r/RExec.hpp>
#include <r/RRoutines.hpp>

#include <session/SessionModuleContext.hpp>

using namespace core;

namespace session {
namespace modules { 
namespace tex {

namespace {

FilePath pdfPathForTexPath(const FilePath& texPath)
{
   return texPath.parent().complete(texPath.stem() + ".pdf");
}

void callSweave(const std::string& file)
{
   // calculate path to R binary
   std::string path = r::exec::rBinaryPath().absolutePath();

   // build args
   core::system::Options args;
   args.push_back(std::make_pair("CMD", "Sweave"));
   args.push_back(std::make_pair(file, ""));

   // call sweave
   Error error = module_context::executeInterruptableChild(path, args);
   if (error)
      LOG_ERROR(error);
}

SEXP rs_callSweave(SEXP fileSEXP)
{
   // call sweave
   callSweave(r::sexp::asString(fileSEXP));<commit_msg>call sweave correctly on windows<commit_after>/*
 * SessionTeX.cpp
 *
 * Copyright (C) 2009-11 by RStudio, Inc.
 *
 * This program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include "SessionTeX.hpp"

#include <string>

#include <core/Log.hpp>
#include <core/Error.hpp>
#include <core/FilePath.hpp>
#include <core/FileSerializer.hpp>

#include <r/RExec.hpp>
#include <r/RRoutines.hpp>

#include <session/SessionModuleContext.hpp>

using namespace core;

namespace session {
namespace modules { 
namespace tex {

namespace {

FilePath pdfPathForTexPath(const FilePath& texPath)
{
   return texPath.parent().complete(texPath.stem() + ".pdf");
}

void callSweave(const std::string& file)
{
   // calculate path to R binary
   std::string path = r::exec::rBinaryPath().absolutePath();

   // build args
   core::system::Options args;

#ifdef _WIN32
   std::string sweaveCmd = "\"Sweave('" + file + "')\"";
   args.push_back(std::make_pair("-e", sweaveCmd));
   args.push_back(std::make_pair("--silent", ""));
#else
   args.push_back(std::make_pair("CMD", "Sweave"));
   args.push_back(std::make_pair(file, ""));
#endif

   // call sweave
   Error error = module_context::executeInterruptableChild(path, args);
   if (error)
      LOG_ERROR(error);
}

SEXP rs_callSweave(SEXP fileSEXP)
{
   // call sweave
   callSweave(r::sexp::asString(fileSEXP));
{'fraction_non_alphanumeric': 0.13655394524959744, 'fraction_numerical': 0.00644122383252818, 'mean_word_length': 4.411149825783972, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5885642', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1020, 'n_words': 266}