nmfs-ost / nmfs-ost/stockplotr
Automating ordering of figures and tables
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 19
- Forks
- 7
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 9
Description
We have custom code in the SE to automate the ordering of figures and tables based on in-text citation. This feature would be nice to have in asar/stockplotr. Maybe you can adapt our approach to work with asar?
The figure number is generated in-text using the function add_figure (see code below) :
Figure r add_figure("FigInitSearch")
If you want to reference multiple figures but not be redundant ("Figures 3-5" instead of "Figures 3,4,5") you can use silent =T
Figures r add_figure("FigLS3New") r add_figure("FigLS4New", silent=T)-r add_figure("FigLS5New"))
The function reads from have an excel file (TablesAndFigures.xlsx) that lists all the tables available and their location (and other features like caption and size)
add_figure <- function(name,setup_location="TablesAndFigures.xlsx",silent=FALSE){
#First check to see if the figure counter exists.
#If it does increment by 1. Otherwise create the counter
if(exists("MyFigs")){
if(!'included' %in% names(MyFigs)){
MyFigs['included'] <<- rep(0,length(MyFigs[,1]))
}
}else{
MyFigs <<- as.data.frame(read_excel(setup_location,sheet="Figures"))
#MyFigs <<- read.csv(file=setup_location)
MyFigs[,'included'] <<- rep(0,length(MyFigs[,1]))
}
fig_sub <- MyFigs[MyFigs[,'Number']==MyFigs[MyFigs[,'Call']==name,'Number'][1],,drop=FALSE]
if(length(fig_sub[,1])==0){
stop(paste0("Error: you referenced a figure call ( ",name," ) that doesn't exist in you figure setup data frame."))
}else{
if(fig_sub[,'included'][1]==0){
if(exists("fig_count")){
fig_count <<- fig_count+1
}else{
fig_count <<- 1
}
if(fig_sub[,'Number'][1]!=fig_count){
MyFigs[MyFigs[,'Number']==fig_count,'Number'] <<- rep((max(as.numeric(MyFigs[,'Number']))+1),length(MyFigs[MyFigs[,'Number']==fig_count,'Number']))
MyFigs[MyFigs[,'Number']==fig_sub[,'Number'][1],'included'] <<- rep(1,length(fig_sub[,1]))
MyFigs[MyFigs[,'Number']==fig_sub[,'Number'][1],'Number'] <<- rep(fig_count,length(fig_sub[,1]))
}else{
MyFigs[MyFigs[,'Number']==fig_sub[,'Number'][1],'included'] <<- rep(1,length(fig_sub[,1]))
}
fig_num <- fig_count
}else{
fig_num <- fig_sub[,'Number'][1]
}
}
if(silent==TRUE){
return("")
}else{
return(fig_num)
}
}
We also have custom code to specify the figure layout on the page (e.g. if we want two figures side by side or one above the other). Happy to share that as well if it's of interest.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposed add_figure function and the TablesAndFigures.xlsx Figures sheet to understand how figure calls, numbering, and silent citations are represented. Then inspect stockplotr's existing figure and table-generation entry points; done should include an agreed approach for ordering figures and tables from in-text citations, with any layout support scoped separately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100