Skip to content

document() recompiles package source code, which requires a NAMESPACE #1016

Closed

Description

@cboettig

Attempting to write a package wrapper around some existing source code. For reasons that are not obvious to me, calling devtools::document() starts the package recompiling. Moreover, this call fails if the package does not have a NAMESPACE file. If I start the package with a manually created NAMESPACE (even a blank one), then devtools::document() runs, recompiling everything, but then refuses to update my NAMESPACE file. Thus it appears impossible to have devtools create a NAMESPACE for the package.

Of course I can hack around this by starting with a NAMESPACE file with the comment

# Generated by roxygen2: do not edit by hand

but this feels wrong. Is there a more elegant work-around out of this catch-22? (Why does document() need to recompile anyhow?) Am I missing something?

Activity

  1. hadley commented on Jan 13, 2016

    @hadley
    Member

    Roxygen is a run-time documentation system - it inspects the objects in the package environment, not just the source code. That means it needs to load_all() the package, which obviously it can't do without compiling any C code.

    Would you mind briefly outlining a series of steps that gets you to this point? Normally the NAMESPACE doesn't matter when compiling code.

  2. cboettig commented on Jan 13, 2016

    @cboettig
    Author

    Apologies for not having a good minimal example, this could be user error from a naive attempt to wrap a C program. Anyway, if you clone https://github.com/cboettig/rappl/tree/testing and run devtools::document() you should see the error about not having a NAMESPACE.

    Here's the run log I see:

    devtools::document()
    Updating rappl documentation
    Loading rappl
    Re-compiling rappl
    '/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore CMD  \
      INSTALL '/home/rstudio/rappl'  \
      --library='/tmp/RtmpDrJUwI/devtools_install_17fbdfe81' --no-R --no-data  \
      --no-help --no-demo --no-inst --no-docs --no-exec --no-multiarch  \
      --no-test-load --preclean 
    
    * installing *source* package ‘rappl’ ...
    rm -f ./PolicyGraph/PolicyGraph.o ./PolicyGraph/PolicyGraphGenerator.o ./Evaluator/EvaluationEngine.o ./Evaluator/EvaluatorSampleEngine.o ./Simulator/SimulationEngine.o ./MathLib/DenseVector.o ./MathLib/MathLib.o ./MathLib/SparseMatrix.o ./MathLib/SparseVector.o ./Algorithms/SARSOP/BinManager.o ./Algorithms/SARSOP/BinManagerSet.o ./Algorithms/SARSOP/Sample.o ./Algorithms/SARSOP/SampleBP.o ./Algorithms/SARSOP/SARSOP.o ./Algorithms/SARSOP/SARSOPPrune.o ./Models/MOMDP/BeliefTransitionMOMDP.o ./Models/MOMDP/ObservationProbabilities.o ./Models/MOMDP/VariableRelation.o ./Models/MOMDP/BooleanVariable.o ./Models/MOMDP/StateTransitionXY.o ./Models/MOMDP/StateTransitionY.o ./Models/MOMDP/MOMDPLite.o ./Models/MOMDP/MOMDP.o ./Models/MOMDP/VariableValue.o ./Models/MOMDP/Variable.o ./Models/MOMDP/StateTransitionXXpY.o ./Models/MOMDP/IVariable.o ./Models/MOMDP/VariableCombined.o ./Models/MOMDP/Rewards.o ./Models/MOMDP/StateTransitionX.o ./Models/MOMDP/BeliefTransitionMOMDPLite.o ./Models/MOMDP/IVariableValue.o ./OfflineSolver/GlobalResource.o ./OfflineSolver/solverUtils.o ./Bounds/AlphaPlane.o ./Bounds/AlphaPlanePool.o ./Bounds/AlphaPlanePoolSet.o ./Bounds/AlphaVectorPolicy.o ./Bounds/BackupAlphaPlaneMOMDP.o ./Bounds/BackupAlphaPlaneMOMDPLite.o ./Bounds/BackupBeliefValuePairMOMDP.o ./Bounds/BackupBeliefValuePairMOMDPLite.o ./Bounds/BeliefValuePair.o ./Bounds/BeliefValuePairPool.o ./Bounds/BeliefValuePairPoolSet.o ./Bounds/BlindLBInitializer.o ./Bounds/FastInfUBInitializer.o ./Bounds/FullObsUBInitializer.o ./Bounds/PruneAlphaPlane.o ./Bounds/PruneBeliefValuePair.o ./Bounds/xml_parse_lib.o ./Core/Actions.o ./Core/VariableContainer.o ./Core/Belief.o ./Core/BeliefCache.o ./Core/BeliefException.o ./Core/BeliefForest.o ./Core/BeliefTreeNode.o ./Core/BeliefWithState.o ./Core/MObject.o ./Core/Observations.o ./Core/States.o ./Core/UniqueBeliefHeap.o ./Parser/Cassandra/Parser.o ./Parser/Cassandra/POMDP.o ./Parser/Cassandra/pomdpCassandraWrapper.o ./Parser/ParserSelector.o ./Parser/POMDPX/FactoredPomdp.o ./Parser/POMDPX/Function.o ./Parser/POMDPX/ObsAct.o ./Parser/POMDPX/PreCEntry.o ./Parser/POMDPX/PreCMatrix.o ./Parser/POMDPX/SparseEntry.o ./Parser/POMDPX/SparseTable.o ./Parser/POMDPX/State.o ./Parser/POMDPX/StateObsAct.o ./Parser/POMDPX/tinystr.o ./Parser/POMDPX/tinyxml.o ./Parser/POMDPX/tinyxmlerror.o ./Parser/POMDPX/tinyxmlparser.o ./Utils/InfoLog.o ./Utils/md5.o ./Utils/md5wrapper.o ./Utils/CPMemUtils.o ./Utils/StatsCollector.o ./Utils/SimulationRewardCollector.o ./Parser/Cassandra/include/pomdp_spec.tab.o ./Parser/Cassandra/include/pomdp_spec.yy.o ./miniposix/getopt.o ./miniposix/getopt1.o ./miniposix/getopt_init.o ./Parser/Cassandra/decision-tree.o ./Parser/Cassandra/imm-reward.o ./Parser/Cassandra/mdpCassandra.o ./Parser/Cassandra/parse_err.o ./Parser/Cassandra/parse_hash.o ./Parser/Cassandra/sparse-matrix.o ./Controller/Controller.o   ./OfflineSolver/solver.o  ./Simulator/Simulator.o  ./Evaluator/Evaluator.o  ./PolicyGraph/PolicyGraph.o  ./PomdpConvertor/convertor.o  ./Controller/testControllerTiger.o 
    rm -f libappl.a pomdpsol pomdpsim pomdpeval polgraph pomdpconvert testControllerTiger
    ERROR: a 'NAMESPACE' file is required
    * removing ‘/tmp/RtmpDrJUwI/devtools_install_17fbdfe81/rappl’
    Error: Command failed (1)
    > 
    

    This seems to be related to the fact that I am using the Makefile from the original C program, which I understand isn't the right thing to do, so perhaps this isn't a problem once I figure out how to write the proper Makevars file in place of it, so perhaps this isn't a real issue. (I have a deal to learn still on that front). I was just surprised by the error.

  3. hadley commented on Jan 13, 2016

    @hadley
    Member

    How did you create the original package? Most ways should give you a dummy/empty NAMESPACE.

  4. cboettig commented on Jan 13, 2016

    @cboettig
    Author

    I created it with devtools::setup() (actually copied a template created with setup()). This created a dummy NAMESPACE (that does not have the #Generated by roxygen2: header), and so Roxygen was refusing to overwrite that. So I deleted the NAMESPACE and wound up with the above error.

  5. lock commented on Sep 18, 2018

    @lock

    This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

  6. locked and limited conversation to collaborators on Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions