Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:09:12+00:00 2026-06-15T07:09:12+00:00

I have a very long script R that plots very complicated data. I only

  • 0

I have a very long script R that plots very complicated data. I only use the plots to have a visual idea of what I am doing but I can compute the results without the plots and obviously not plotting anything makes things much faster. Occasionally, however, I still need to visualize what the program does to keep debugging it.

To achieve this plotting ‘on or off’ switch I am following this strategy.

For each line that has commands relevant to the plotting functions of the script, I have a specific commented tag #toplot at the end of each relevant line. Using the power of regex substitution I then comment / uncomment these lines with the following commands.

The sample code:

a <- c(1:10)
b <- a/sin(a)
png('sin.png') #toplot
plot(b)        #toplot
dev.off()      #toplot
print(b)

To comment the ‘tagged’ lines:

  :%s/.\+#toplot/###commline###\0/g

I get this:

a <- c(1:10)
b <- a/sin(a)
###commline###    png('sin.png') #toplot
###commline###    plot(b)        #toplot
###commline###    dev.off()      #toplot
print(b)

To uncomment them:

  :%s/###commline###//g

I get this:

a <- c(1:10)
b <- a/sin(a)
png('sin.png') #toplot
plot(b)        #toplot
dev.off()      #toplot
print(b)

I am no computer scientist so I don’t know if there is a better, more elegant way of performing these kind of operations.

EDIT: It is important to mention that for plotting my data I need to go through many rounds of calculations and transformations so the different kinds of data fit in the plotting device. To perform these operations I use the history, I go up and down depending what I need.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:09:13+00:00Added an answer on June 15, 2026 at 7:09 am

    Your approach looks fine to me.

    If you can come up with a regular expression that captures all plot-related lines, you could do away with the #toplot marker, and let the comment substitution directly work on that instead.

    You didn’t mention whether you re-type the substitutions or use the history. I would definitely define a buffer-local command (and/or mapping) for that:

    autocmd FileType r command! -buffer Comment %s/.\+#toplot/###commline###\0/g
    autocmd FileType r command! -buffer Uncomment %s/###commline###//g
    

    (Or put the :commands! into ~/.vim/ftplugin/r_commands.vim.)

    If you properly define the 'comments' setting for your filetype (e.g. add b:###commline###) and 'commentstring', you may also be able to use one of the general comment plugins (like The NERD Commenter), which offer nice mappings to toggle a comment on/off.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very long running script that is doing a pretty significant amount
I have a very painful slow script that gets lots of data from MySQL
I have a perl script that receives 3 arugments. First argument is very long
I have a script that compiles a list of items that can be very
I have a script that is very long to execute, so when i run
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
I have a very long javascript (so long that it's too long to escape
We have a very long form that has a number of fields and 2
As background I have a very long ID that too long to display in
I have a very simple perl script that moves files (don't ask why i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.