Nat  Grady

Nat Grady

1666941420

Datapasta: On top Of Spaghetti, All Covered in Cheese....

datapasta 3.1.1 ‘Leave to Simmer’

The Goods

pow!

Introducing datapasta

datapasta is about reducing resistance associated with copying and pasting data to and from R. It is a response to the realisation that I often found myself using intermediate programs like Sublime to munge text into suitable formats. Addins and functions in datapasta support a wide variety of input and output situations, so it (probably) "just works". Hopefully tools in this package will remove such intermediate steps and associated frustrations from our data slinging workflows.

Prerequisites

  • Linux users will need to install either xsel or xclip. These applications provide an interface to X selections (clipboard-like).
    • For example: sudo apt-get install xsel - it's 72kb...
  • Windows and MacOS have nothing extra to do.

Installation

R Universe (preferred)

install with R universe repo:

install.packages(
   "datapasta", 
   repos = c(mm = "https://milesmcbain.r-universe.dev", getOption("repos")))

Set the keyboard shortcuts using Tools -> Addins -> Browse Addins, then click Keyboard Shortcuts...

CRAN (outdated)

For now, no further versions of datapasta will be going to CRAN. There are some known bugs in the CRAN version that have been fixed in 3.1.1.

install.packages("datapasta")

Usage

Use with RStudio

Getting data into source

At the moment this package contains these RStudio addins that paste data to the cursor:

  • tribble_paste which pastes a table as a nicely formatted call to tibble::tribble()
    • Recommend Ctrl + Shift + t as shortcut.
    • Table can be delimited with tab, comma, pipe or semicolon.
  • vector_paste which will paste delimited data as a vector definition, e.g. c("a", "b") etc.
    • Recommend Ctrl + Alt + Shift + v as shortcut.
  • vector_paste_vertical which will paste delimited data as a vertically formatted vector definition.
    • Recommend Ctrl + Shift + v as shortcut
    • example output:
c("Mint",
"Fedora",
"Debian",
"Ubuntu",
"OpenSUSE")
  • df_paste which pastes a table on the clipboard as a standard data.frame definition rather than a tribble call. This has certain advantages in the context of reproducible examples and educational posts. Many thanks to Jonathan Carroll for getting this rolling and coding the bulk of the feature.
    • Recommend Ctrl + Alt + Shift + d as shortcut.
  • dt_paste which is the same as df_paste, but for data.table.

Massaging data in source

There are two Addins that can help with creating and aligning data in your editor:

Fiddle Selection will perform magic on a selection. It can be used to:

  • Turn raw data delimited by any combination of commas, spaces, and newlines into a c() expression
  • Pivot a c() expr between horizontal and vertical layout.
  • Reflow messy tribble() and data.frame() exprs.
  • Recommend Ctrl +Shift + f as shortcut.

Toggle Vector Quotes will toggle a c() expr between all elements wrapped in "" and all bare unquoted form. Handy in combination with above to save mucho keystrokes.

  • Recommend Ctrl +Shift + q as shortcut.

Getting Data out of an R session

There are two R functions available that accept R objects and output formatted text for pasting to a reprex or other application:

dpasta accepts tibbles, data.frames, and vectors. Data is output in a format that matches in input class. Formatted text is pasted at the cursor.

dmdclip accepts the same inputs as dpasta but inserts the formatted text onto the clipboard, preceded by 4 spaces so that is can be as pasted as a preformatted block to Github, Stackoverflow etc.

Use with other editors

The only hard dependency of datapasta is readr for type guessing. All the above *paste functions can be called directly instead of as an addin, and will fall back to console output if the rstudioapi is not available.

On system without access to the clipboard (or without clipr installed) datapasta can still be used to output R objects from an R session. dpasta is probably the only function you care about in this scenario.

Custom Installation

datapasta imports clipr and rstudioapi so as to make installation smooth and easy for most users. If you wish to avoid installing an rstudioapi you will never use you can use:

  • install.packages("datapasta", dependencies = "Depends").
  • Followed by install.packages("clipr") to enable clipboard features.

Pitfalls

  • tribble_paste works well with CSVs, excel files, and html tables, but is currently brittle with respect to irregular table structures like merged cells or multi-line column headings. For some reason Wikipedia seems chock full of these. :(
  • Quoted csv data, where the quotes contain commas will not be parsed correctly.
  • Nested list columns have limited support with tribble_paste()/dpasta(). Nested lists of length 1 fail unless all are length 1 - It's complicated. You still get some output so it might be viable to fix and reflow with Fiddle Selection. Tread with caution.

Prior art

This package is made possible by mdlincon's clipr, and Hadley's packages tibble and readr (for data-type guessing). I especially appreciate clipr's thoughtful approach to the clipboard on Linux, which pretty much every other R clipboard package just nope'd out on.

Future developments

I am interested in expanding the types of objects supported by the output functions dpasta. I would also like to eventually have Fiddle Selection to pivot function calls and named vectors. Feel free to contribute your ideas to the open issues.

Bonus

0 to datapasta in 64 seconds via a video vignette:

Datapasta in 64 seconds

Download Details:

Author: MilesMcBain
Source Code: https://github.com/MilesMcBain/datapasta 
License: View license

#r #clipboard #excel 

Datapasta: On top Of Spaghetti, All Covered in Cheese....
Rupert  Beatty

Rupert Beatty

1665945660

Clipy: Clipboard Extension App for MacOS

Clipy

Clipy is a Clipboard extension app for macOS.


Requirement: macOS 10.10 Yosemite or higher

Distribution Site : https://clipy-app.com

Development Environment

  • macOS 10.13 High Sierra
  • Xcode 9.3
  • Swift 4.1

How to Build

  1. Move to the project root directory
  2. Open Clipy.xcworkspace on Xcode.
  3. build.

Mavericks Support

v1.1.2 is the final version of Mavericks support.
Download v1.1.2 release

Contributing

  1. Fork it ( https://github.com/Clipy/Clipy/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Localization Contributors

Clipy is looking for localization contributors.
If you can cooperate, please see CONTRIBUTING.md

Distribution

If you distribute derived work, especially in the Mac App Store, I ask you to follow two rules:

  1. Don't use Clipy and ClipMenu as your product name.
  2. Follow the MIT license terms.

Thank you for your cooperation.

Download Details:

Author: Clipy
Source Code: https://github.com/Clipy/Clipy 
License: MIT license

#swift #macos #clipboard 

Clipy: Clipboard Extension App for MacOS
Monty  Boehm

Monty Boehm

1662532699

5 Best React Clipboard Libraries

In today's post we will learn about 5 Best React Clipboard Libraries. 

1 - AG-grid

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

Install dependencies

$ npm install --save ag-grid-community

Add a placeholder to HTML

<div id="myGrid" style="height: 150px; width: 600px" class="ag-theme-alpine"></div>

Import the grid and styles

import { Grid } from 'ag-grid-community';

import 'ag-grid-community/styles//ag-grid.css';
import 'ag-grid-community/styles//ag-theme-alpine.css';

Set configuration

var gridOptions = {
	columnDefs: [
		{ headerName: 'Make', field: 'make' },
		{ headerName: 'Model', field: 'model' },
		{ headerName: 'Price', field: 'price' }
	],
	rowData: [
		{ make: 'Toyota', model: 'Celica', price: 35000 },
		{ make: 'Ford', model: 'Mondeo', price: 32000 },
		{ make: 'Porsche', model: 'Boxster', price: 72000 }
	]
};

Initialise the grid

var eGridDiv = document.querySelector('#myGrid');
new Grid(eGridDiv, this.gridOptions);

View on Github

2 - React-copy-to-clipboard

Copy-to-clipboard React component

Installation

NPM

npm install --save react-copy-to-clipboard

Don't forget to manually install peer dependencies (react) if you use npm@3.

1998 Script Tag:

<script src="https://unpkg.com/react@16.0.0/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-copy-to-clipboard/build/react-copy-to-clipboard.js"></script>
(Module exposed as `CopyToClipboard`)

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import {CopyToClipboard} from 'react-copy-to-clipboard';

class App extends React.Component {
  state = {
    value: '',
    copied: false,
  };

  render() {
    return (
      <div>
        <input value={this.state.value}
          onChange={({target: {value}}) => this.setState({value, copied: false})} />

        <CopyToClipboard text={this.state.value}
          onCopy={() => this.setState({copied: true})}>
          <span>Copy to clipboard with span</span>
        </CopyToClipboard>

        <CopyToClipboard text={this.state.value}
          onCopy={() => this.setState({copied: true})}>
          <button>Copy to clipboard with button</button>
        </CopyToClipboard>

        {this.state.copied ? <span style={{color: 'red'}}>Copied.</span> : null}
      </div>
    );
  }
}

const appRoot = document.createElement('div');
document.body.appendChild(appRoot);
ReactDOM.render(<App />, appRoot);

View on Github

3 - React-use-clipboard

React hook that provides copy to clipboard functionality.

Install

You can install react-use-clipboard with NPM or Yarn.

npm install react-use-clipboard
yarn add react-use-clipboard

Usage

Here's how to use react-use-clipboard:

import useClipboard from "react-use-clipboard";

function App() {
  const [isCopied, setCopied] = useClipboard("Text to copy");

  return (
    <button onClick={setCopied}>
      Was it copied? {isCopied ? "Yes! 👍" : "Nope! 👎"}
    </button>
  );
}

You can reset the isCopied value after a certain amount of time with the successDuration option.

import useClipboard from "react-use-clipboard";

function App() {
  const [isCopied, setCopied] = useClipboard("Text to copy", {
    // `isCopied` will go back to `false` after 1000ms.
    successDuration: 1000,
  });

  return (
    <button onClick={setCopied}>
      Was it copied? {isCopied ? "Yes! 👍" : "Nope! 👎"}
    </button>
  );
}

This package only works in versions of React that support Hooks.

View on Github

4 - Welcome-ui

Here you'll find all the core components you need to create a delightful webapp. Customizable design system from Welcome to the jungle (@WTTJ) with react, typescript, styled-components, reakit and a lot of love 💛

Installation

1 - Install the peer dependencies listed below:

yarn add @xstyled/styled-components react styled-components

2 - Install the the core component and any other components you need for your webapp e.g. if you need just a button…

yarn add @welcome-ui/core @welcome-ui/button

Import library & Theme

Getting started

import React from 'react'
import { createTheme, WuiProvider } from '@welcome-ui/core'
import { Button } from '@welcome-ui/button'

// Add theme options (if you want)
const options = {
  defaultFontFamily: 'Helvetica',
  headingFontFamily: 'Georgia',
  colors: {
    primary: {
      500: '#124C80',
    },
    success: {
      500: '#32CD32',
    },
  },
}

// Create your theme
const theme = createTheme(options)
export default function Root() {
  return (
    // Wrap your components with <WuiProvider /> with your theme
    <WuiProvider
      theme={theme}
      // Will inject a CSS reset with normalizer
      hasGlobalStyle
      // Will show the focus ring on keyboard navigation only
      shouldHideFocusRingOnClick
    >
      <Button>Welcome!</Button>
    </WuiProvider>
  )
}

View on Github

5 - React-hook/useCopy()

A React hook for copying text to the clipboard

Quick Start

import useCopy from '@react-hook/copy'

const Component = (props) => {
  const {copied, copy, reset} = useCopy(
    'This text will be copied to the clipboard'
  )

  return <a onClick={copy}>{copied === false ? 'Copy' : 'Copied'}</a>
}

View on Github

Thank you for following this article. 

#react #clipboard 

5 Best React Clipboard Libraries
Nat  Grady

Nat Grady

1661558160

Rclipboard: Clipboard.js for R/Shiny Applications

rclipboard: clipboard.js for R/Shiny Applications

Introduction

clipboard.js is a super light javascript framework, which provides copy-to-clipboard functionality using HTML5. The simple rclipboard R package is simple and leverages clipboard.js functionality to provide a reactive copy-to-clipboard UI button component, called rclipButton, and a reactive copy-to-clipboard UI link component, called rclipLink, for Shiny R applications.

Example

This example works when deployed on a Shiny server or when it is run from RStudio. However, because of limitations in the web engine of RStudio versions prior to 1.2, the rclipButton does not work natively when the application is run locally. A workaround must be implemented in the form of an observeEvent associated to the rclipButton and using the clipr function from the clipr package.

This workaround is not required if you run your applications in RStudio versions >= 1.2.

library(rclipboard)
library(shiny)

# The UI
ui <- bootstrapPage(
  
  rclipboardSetup(),
  
  # Add a text input
  textInput("copytext", "Copy this:", "Zlika!"),

  # UI ouputs for the copy-to-clipboard buttons
  uiOutput("clip"),
  
  # A text input for testing the clipboard content.
  textInput("paste", "Paste here:")
  
)

# The server
server <- function(input, output) {

  # Add clipboard buttons
  output$clip <- renderUI({
    output$clip <- renderUI({
      rclipButton(
        inputId = "clipbtn",
        label = "rclipButton Copy",
        clipText = input$copytext, 
        icon = icon("clipboard")
      )
    })
  })
  
  # Workaround for execution within RStudio version < 1.2
  if (interactive()){
    observeEvent(input$clipbtn, clipr::write_clip(input$copytext))
  }
  
}

shinyApp(ui = ui, server = server)

Download Details:

Author: Sbihorel
Source Code: https://github.com/sbihorel/rclipboard 
License: View license

#r #clipboard 

Rclipboard: Clipboard.js for R/Shiny Applications
Nat  Grady

Nat Grady

1661095800

Copydat: Copy R data to clipboard

copydat

What is it?

copydat lets you copy a data.frame to the clipboard using the ...

... RStudio GUI. Just highlight (in your source console) the name of the data.frame you want to copy. (Examples: iris; mtcars). Click Addins > Copy data, and you're done.

... R console. Like this: mtcars %>% Copy(dat2tsv) # or dat2rtf. Paste away!

Supported formats:

  • TSV (to paste into a spreadsheet)
  • RTF (to paste into a document or an email)

It's a work in progress. TODO:

  • Support for platforms other than OS X. Just submit a pull request re: clipboard(). Easy! :-D
  • Easy attribution/provenance (comment() --> table caption?)
  • More formats

Thanks to @Rstudio and @kevinushey for RStudio Addins and the great examples. And thanks to @schaffman5 for the rtf package!

Installation

if (!requireNamespace("devtools", quietly = TRUE))
  install.packages("devtools")

devtools::install_github("BAAQMD/copydat")

Download Details:

Author: BAAQMD
Source Code: https://github.com/BAAQMD/copydat 

#r #dat #copy #clipboard 

Copydat: Copy R data to clipboard
Nat  Grady

Nat Grady

1661076300

Datapasta: On top Of Spaghetti, All Covered in Cheese

datapasta 3.1.1 'Leave to Simmer'

The Goods

pow!

Introducing datapasta

datapasta is about reducing resistance associated with copying and pasting data to and from R. It is a response to the realisation that I often found myself using intermediate programs like Sublime to munge text into suitable formats. Addins and functions in datapasta support a wide variety of input and output situations, so it (probably) "just works". Hopefully tools in this package will remove such intermediate steps and associated frustrations from our data slinging workflows.

Prerequisites

  • Linux users will need to install either xsel or xclip. These applications provide an interface to X selections (clipboard-like).
    • For example: sudo apt-get install xsel - it's 72kb...
  • Windows and MacOS have nothing extra to do.

Installation

R Universe (preferred)

  1. install with R universe repo:
install.packages(
   "datapasta", 
   repos = c(mm = "https://milesmcbain.r-universe.dev", getOption("repos")))
  1. Set the keyboard shortcuts using Tools -> Addins -> Browse Addins, then click Keyboard Shortcuts...

CRAN (outdated)

For now, no further versions of datapasta will be going to CRAN. There are some known bugs in the CRAN version that have been fixed in 3.1.1.

  1. install.packages("datapasta")

Usage

Use with RStudio

Getting data into source

At the moment this package contains these RStudio addins that paste data to the cursor:

  • tribble_paste which pastes a table as a nicely formatted call to tibble::tribble()
    • Recommend Ctrl + Shift + t as shortcut.
    • Table can be delimited with tab, comma, pipe or semicolon.
  • vector_paste which will paste delimited data as a vector definition, e.g. c("a", "b") etc.
    • Recommend Ctrl + Alt + Shift + v as shortcut.
  • vector_paste_vertical which will paste delimited data as a vertically formatted vector definition.
    • Recommend Ctrl + Shift + v as shortcut
    • example output:
c("Mint",
"Fedora",
"Debian",
"Ubuntu",
"OpenSUSE")
  • df_paste which pastes a table on the clipboard as a standard data.frame definition rather than a tribble call. This has certain advantages in the context of reproducible examples and educational posts. Many thanks to Jonathan Carroll for getting this rolling and coding the bulk of the feature.
    • Recommend Ctrl + Alt + Shift + d as shortcut.
  • dt_paste which is the same as df_paste, but for data.table.

Massaging data in source

There are two Addins that can help with creating and aligning data in your editor:

Fiddle Selection will perform magic on a selection. It can be used to:

  • Turn raw data delimited by any combination of commas, spaces, and newlines into a c() expression
  • Pivot a c() expr between horizontal and vertical layout.
  • Reflow messy tribble() and data.frame() exprs.
  • Recommend Ctrl +Shift + f as shortcut.

Toggle Vector Quotes will toggle a c() expr between all elements wrapped in "" and all bare unquoted form. Handy in combination with above to save mucho keystrokes.

  • Recommend Ctrl +Shift + q as shortcut.

Getting Data out of an R session

There are two R functions available that accept R objects and output formatted text for pasting to a reprex or other application:

dpasta accepts tibbles, data.frames, and vectors. Data is output in a format that matches in input class. Formatted text is pasted at the cursor.

dmdclip accepts the same inputs as dpasta but inserts the formatted text onto the clipboard, preceded by 4 spaces so that is can be as pasted as a preformatted block to Github, Stackoverflow etc.

Use with other editors

The only hard dependency of datapasta is readr for type guessing. All the above *paste functions can be called directly instead of as an addin, and will fall back to console output if the rstudioapi is not available.

On system without access to the clipboard (or without clipr installed) datapasta can still be used to output R objects from an R session. dpasta is probably the only function you care about in this scenario.

Custom Installation

datapasta imports clipr and rstudioapi so as to make installation smooth and easy for most users. If you wish to avoid installing an rstudioapi you will never use you can use:

  • install.packages("datapasta", dependencies = "Depends").
  • Followed by install.packages("clipr") to enable clipboard features.

Pitfalls

  • tribble_paste works well with CSVs, excel files, and html tables, but is currently brittle with respect to irregular table structures like merged cells or multi-line column headings. For some reason Wikipedia seems chock full of these. :(
  • Quoted csv data, where the quotes contain commas will not be parsed correctly.
  • Nested list columns have limited support with tribble_paste()/dpasta(). Nested lists of length 1 fail unless all are length 1 - It's complicated. You still get some output so it might be viable to fix and reflow with Fiddle Selection. Tread with caution.

Prior art

This package is made possible by mdlincon's clipr, and Hadley's packages tibble and readr (for data-type guessing). I especially appreciate clipr's thoughtful approach to the clipboard on Linux, which pretty much every other R clipboard package just nope'd out on.

Future developments

I am interested in expanding the types of objects supported by the output functions dpasta. I would also like to eventually have Fiddle Selection to pivot function calls and named vectors. Feel free to contribute your ideas to the open issues.

Bonus

0 to datapasta in 64 seconds via a video vignette:

Datapasta in 64 seconds

Download Details:

Author: Milesmcbain
Source Code: https://github.com/milesmcbain/datapasta 
License: View license

#r #clipboard #excel 

Datapasta: On top Of Spaghetti, All Covered in Cheese
Nat  Grady

Nat Grady

1661064300

Clipr: R Functions for Reading and Writing From The System Clipboard

clipr  

Simple utility functions to read and write from the system clipboards of Windows, OS X, and Unix-like systems (which require either xclip or xsel.)

Installation

Install from CRAN

install.packages("clipr")

Or try the development version

remotes::install_github("mdlincoln/clipr")

Usage

clipr is pipe-friendly, and will default to returning the same object that was passed in.

library("clipr")
#> Welcome to clipr. See ?write_clip for advisories on writing to the clipboard in R.

res <- write_clip(c("Text", "for", "clipboard"))
res
#> [1] "Text"      "for"       "clipboard"

cb <- read_clip()
cb
#> [1] "Text"      "for"       "clipboard"

To capture the string that clipr writes to the clipboard, specify return_new = TRUE. Character vectors with length > 1 will be collapsed with system-appropriate line breaks, unless otherwise specified

cb <- write_clip(c("Text", "for", "clipboard"), return_new = TRUE)
cb
#> [1] "Text\nfor\nclipboard"

cb <- write_clip(c("Text", "for", "clipboard"), breaks = ", ", return_new = TRUE)
cb
#> [1] "Text, for, clipboard"

write_clip also tries to intelligently handle data.frames and matrices, rendering them with write.table so that they can be pasted into a spreadsheet like Excel.

tbl <- data.frame(a = c(1, 2, 3), b = c(4, 5, 6))
cb <- write_clip(tbl, return_new = TRUE)
cb
#> [1] "a\tb\n1\t4\n2\t5\n3\t6"

read_clip_tbl will try to parse clipboard contents from spreadsheets into data frames directly.

Developing with clipr

See the “Developing with clipr” vignette included with this package for advisories on writing code that calls clipr functions.

Nice uses of clipr

(a non-comprehensive list)

  1. reprex by @jennybc takes R code on the clipboard and renders a reproducible example from it, ready to then paste on to GitHub, Stack Overflow, or the like.
  2. datapasta by @milesmcbain eases the copying and pasting of R objects in and out of different sources (Excel, Google Sheets).

Matthew Lincoln

Download Details:

Author: mdlincoln
Source Code: https://github.com/mdlincoln/clipr 

#r #clipboard #rstats 

Clipr: R Functions for Reading and Writing From The System Clipboard
Nat  Grady

Nat Grady

1661010300

Imageclipr: Copy Image From Clipboard into RMarkdown .Rmd File

imageclipr

RStudio Addin: Copy images from clipboard into RMarkdown .Rmd files.

Usage of imageclipr

Installation

devtools::install_github('Timag/imageclipr')

Dependencies

R packages library(rstudioapi), (library(rmarkdown) for markdown files)

For linux xclip is required. For debian, ubuntu,... install it with:

sudo apt-get install xclip 

Open issues

  • can not:

-- copy and paste image and text together

-- copy and paste an image by copying the file in the explorer

Technical walkthrough

(highlevel): https://stackoverflow.com/questions/55541345/copy-and-paste-an-image-from-clipboard-to-rmarkdown-rmd-code

Usage

Select the addin

Note: You will see "Paste Img to Rmd file" instead of "Insert Image".

Addin selection

Adding a keyboard shortcut (Recommended)

In RStudio go to Tools - Modify Keyboard Shortcuts...

Note: You will see "Paste Img to Rmd file" instead of "Insert Image".

Find Shortcuts

Modify Shortcuts

(This project is part of my life long application to RStudio :))

Download Details:

Author: Toniiiio
Source Code: https://github.com/Toniiiio/imageclipr 
License: View license

#r #markdown #clipboard #image 

Imageclipr: Copy Image From Clipboard into RMarkdown .Rmd File
Nat  Grady

Nat Grady

1661006340

RStudio-Addin-Snippets: RStudio Add-in to Copy Data To Clipboard

snippets-addin

RStudio add-in to add some code snippets, or help with code editing. It is aimed to be used on Windows. It requires RStudio (>= 0.99.1111) and rstudioapi (>= 0.5-1).

Insert and reformat pipe

This functionality inserts pipes at the current position(s) of the cursor(s) or replaces all selections. It reformats pipe(s) surroundings to achieve following format:

sub <- data %>%
    select(column.1, column.2) %>%
        filter(column.1 > x) %>%
            group_by(column.1) %>%
                summarise(n=n_distinct(column.2)) %>%
                    ungroup
  • exactly one space before %>%
  • line cannot start with %>% (unless it is first line of the file).
    • It will find last non-empty line before the cursor position.
  • new line after %>%
  • next line will be indented as the current line is + N spaces;
    • where N is dependent on the RStudio settings
  • then it's followed by the next word, or it is the end of the line.

Reverse slashes

This functionality is especially useful, when copying paths in Windows.

It will reverse all slashes either in the selected block(s) of code, or if there is no selection (or only whitespace is selected), it will reverse all slashes in the clipboard and paste it to the current cursor(s) position(s).

Copy data to clipboard

At the moment this is Windows only function.

Function will copy the content of the variable 'under the cursor' into the clipboard. It will be represented as a tab separated value for an easy paste to MS Excel.

There is no need to precisely select the name of the variable. Cursor can be placed anywhere in the name, or variable name needs to be first valid name in the code selection. Add-in will adjust the selection. In the case that it is not possible to generate tsv, message will be written to the console. Otherwise tsv will be 'silently' copied to clipboard without any messages.

At the moment following data structures are supported:

Vectors

Vectors are represented in a horizontal fashion. If they are named, then first row will contain names and second values. If they are unnamed then only one row with values is copied into the clipboard.

Matrices

Value copied to clipboard will either have M x N or (M+1) x N, M x (N+1) or (M+1) x (N+1) cells, where M and N are matrix dimensions. If matrix has specified columns names and/or rows names than they will be displayed in the first column and/or row.

In the case that both columns' names and rows' names are specified, the content of the top left cell will be constructed from dimensions' names, if they exist; in the following format: Rows names dimension name, backslash, columns names dimension name. Examples below shows all cases. If dimensions are not named, then variable name will be used.

mat.1 <- matrix( 1:9
               , nrow=3
               , dimnames=list( rows=letters[1:3]
                              , columns=letters[24:26]
                              )
               )
rows\columnsxyz
a147
b258
c369
mat.2 <- matrix( 1:9
               , nrow=3
               , dimnames=list(         letters[1:3]
                              , columns=letters[24:26]
                              )
               )
\columnsxyz
a147
b258
c369
mat.3 <- matrix( 1:9
               , nrow=3
               , dimnames=list( rows=letters[1:3]
                              ,      letters[24:26]
                              )
               )
rows\xyz
a147
b258
c369
mat.4 <- matrix( 1:9
               , nrow=3
               , dimnames=list( letters[1:3]
                              , letters[24:26]
                              )
               )
mat.4xyz
a147
b258
c369

Data frames

Data frames act as matrices.

Arrays

1D arrays

1D arrays act as vectors.

2D arrays

2D arrays act as matrices.

3+D arrays

3+D arrays will be flatten into a matrix. Matrix will have N+1 columns where N is a number of dimensions and M or M+1 rows, where M is a product of array dimensions. E.g. if array has following dimensions dim=c(2, 4, 2), then the output table will have N=3+1=4 columns and M=242=16 rows. If array dimensions are named, then header row will be added. First N columns will be take names from dimensions' names and the last column will be named after variable. Missing names will stay empty.

See examples below.

Example 1

3D array with defined dimension names. One of the dimension names is missing.

(arr.3d <- array( 1:24
                , dim=c(3, 4, 2)
                , dimnames=list( x=c('a', 'b', 'c')
                               ,   c('k', 'l', 'm', 'n')
                               , z=c('x', 'y')
                               )
                )
)

Print out:

, , z = x

x   k l m  n
  a 1 4 7 10
  b 2 5 8 11
  c 3 6 9 12

, , z = y

x    k  l  m  n
  a 13 16 19 22
  b 14 17 20 23
  c 15 18 21 24

In clipboard:

x zarr.3d
akx1
bkx2
ckx3
alx4
blx5
clx6
amx7
bmx8
cmx9
anx10
bnx11
cnx12
aky13
bky14
cky15
aly16
bly17
cly18
amy19
bmy20
cmy21
any22
bny23
cny24

Example 2

3D array without named dimensions.

(arr.3d <- array( 1:24
                , dim=c(3, 4, 2)
                , dimnames=list( c('a', 'b', 'c')
                               , c('k', 'l', 'm', 'n')
                               , c('x', 'y')
                               )
                )
)

Print out:

, , x

  k l m  n
a 1 4 7 10
b 2 5 8 11
c 3 6 9 12

, , y

   k  l  m  n
a 13 16 19 22
b 14 17 20 23
c 15 18 21 24

In clipboard:

  • the empty top row won't be in the output - markdown doesn't support tables without headers
    
akx1
bkx2
ckx3
alx4
blx5
clx6
amx7
bmx8
cmx9
anx10
bnx11
cnx12
aky13
bky14
cky15
aly16
bly17
cly18
amy19
bmy20
cmy21
any22
bny23
cny24

Example 3

Bare 3D array.

(arr.3d <- array(1:24, dim=c(3, 4, 2)))

Print out:

, , 1

     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12

, , 2

     [,1] [,2] [,3] [,4]
[1,]   13   16   19   22
[2,]   14   17   20   23
[3,]   15   18   21   24

In clipboard:

  • the empty top row won't be in the output - markdown doesn't support tables without headers
    
AAA1
BAA2
CAA3
ABA4
BBA5
CBA6
ACA7
BCA8
CCA9
ADA10
BDA11
CDA12
AAB13
BAB14
CAB15
ABB16
BBB17
CBB18
ACB19
BCB20
CCB21
ADB22
BDB23
CDB24

Tables

"1D" tables

"1D" tables act as vectors.

"2D" tables

"2D" tables act as matrices.

"3+D" tables

"3+D" tables act as 3+D arrays.

Collection of badges

Download Details:

Author: sfr
Source Code: https://github.com/sfr/RStudio-Addin-Snippets 
License: GPL-2.0 license

#r #rstudio #clipboard 

RStudio-Addin-Snippets: RStudio Add-in to Copy Data To Clipboard
Nat  Grady

Nat Grady

1660893480

RmdImgPaste: Copy Images From Clipboard to Rmd Files Or Blogdown Posts

RmdImgPaste

RStudio Addin: Copy images from clipboard into .Rmd files or a blogdown post.

Installation

devtools::install_github('xiaoa6435/RmdImgPaste')

Dependencies

  • rstudioapi
  • for linux user, xlip is needed
  • for windows 7, powershell need updated to 5.1

Technical walkthrough

how to read image from clipboard?

in macos, exec script like this:

osascript -e '
  set theFile to (open for access POSIX file "test.png" with write permission)
  try
    write (the clipboard as «class PNGf») to theFile
  end try
  close access theFile'

in window

powershell -sta '
  Add-Type -AssemblyName System.Windows.Forms;,
  if ($([System.Windows.Forms.Clipboard]::ContainsImage())) {
    [System.Drawing.Bitmap][System.Windows.Forms.Clipboard]::GetDataObject(
      ).getimage().Save("test.png", [System.Drawing.Imaging.ImageFormat]::Png)
  }'

in linux (not test):

xclip -selection clipboard -t image/png -o > "test.png"

if this Addin not work, you can test if this scipt can can generate test.png file when you have a image on clipboard

where is paste image?

for a general Rmd files, all paste image in curr_path/.assets/, named like rmd-img-paste-%Y%m%d%H%M%s.png. If you don't like it, you can specify a subfloder by options(rmarkdown.paste_image_dir = 'you_floder').

for a blogdown post(.Rproj have attr like 'BuildType: Website' and in content/../.., you can override it by options(rmarkdown.is_blogdown_post = FALSE), all paste image in static/post/postname_files/, and insert code like ![](/post/postname_files/rmd-img-paste-%Y%m%d%H%M%s.png).

you can specify a baseurl by options(rmarkdown.blogdown_baseurl = 'you_baseurl').

Usage

Tools -> Modify Keyboard Shortcuts -> RmdImgPaste,Customize a shortcut (for example, cmd + v), then you can just use 'cmd + v' paste image into a blogdown post or a Rmd file

Acknowledgements

this code is based on https://github.com/Timag/imageclipr and make some changes:

  • remove python dependency
  • remove shiny, only shortcuts
  • add support for blogdown post

Download Details:

Author: Xiaoa6435
Source Code: https://github.com/xiaoa6435/RmdImgPaste 

#r #clipboard #image 

RmdImgPaste: Copy Images From Clipboard to Rmd Files Or Blogdown Posts

XClipboard.jl: Xlib Clipboard Bindings for Julia

XClipboard.jl: Copy and paste in Julia on XWindows systems

This is a partial translation of Ed Rosten's [x_clipboard] (https://github.com/edrosten/x_clipboard), a nearly complete demonstration of how to use the clipboard and drag and drop in X11.

(See also here for a nice overview.)

At this point, only pasting into Julia is implemented.

Copy-and-paste in general (and on X11 in particular) is actually a rather tedious experience. It would be great if there were a higher level, preferably cross-platform library which took care of this, but as of mid-2013, I couldn't find one.

Note that Julia Base has a clipboard() command that already works for text-based copying. xclipboard() is meant to allow any kind of data to be pasted, but currently, the parsing of non-text data is up to the individual.

Functions

xclipboard([t1, [t2, ...]])   Get the current contents of the X11
                              clipboard, optionally specifying target
                              types.

xclipboard_targets()          Get a list of possible target types
                              for the current selection

decodemime(::MIME{mime}, x)   Used to decode a particular target
                              type.  Currently handles text, and
                              returns other target types as raw
                              byte arrays.

Example

julia> using XClipboard

julia> xclipboard_targets()
10-element Array{MIME{mime},1}:
 MIME type TIMESTAMP               
 MIME type TARGETS                 
 MIME type MULTIPLE                
 MIME type SAVE_TARGETS            
 MIME type UTF8_STRING             
 MIME type COMPOUND_TEXT           
 MIME type TEXT                    
 MIME type STRING                  
 MIME type text/plain;charset=utf-8
 MIME type text/plain              

julia> xclipboard()
"Julia: A fresh approach to technical computing"

julia> xclipboard("UTF8_STRING")
"Julia: A fresh approach to technical computing"

julia> xclipboard("text/plain")
"Julia: A fresh approach to technical computing"

julia> xclipboard("text")
ERROR: Requested clipboard target(s) not found.
 in xclipboard at /home/kmsquire/.julia/v0.3/XClipboard/src/XClipboard.jl:37
 in xclipboard at /home/kmsquire/.julia/v0.3/XClipboard/src/XClipboard.jl:45

Misc

Binary data (such as images) can be received from the clipboard. However, decoding is currently left up to the individual.

Images, in particular, seem to (almost?) always be available as image/bmp; however, there is currently no bmp decoder in Julia.

Download Details:

Author: Kmsquire
Source Code: https://github.com/kmsquire/XClipboard.jl 
License: View license

#julia #clipboard 

XClipboard.jl: Xlib Clipboard Bindings for Julia
Elian  Harber

Elian Harber

1653049500

Go-clip: A Minimalistic Clipboard Manager for Mac

Go-clip

A minimalistic clipboard manager for Mac. 

Demo

Disclaimer

This application is intended to help you manage multiple short-lived clippings, it is not meant as a password store or a place to save important data for later use.

The application DOES NOT SAVE YOUR TEXT anywhere on your computer. It is all in-memory, you lose all your data if you quit the application. So do not worry about your copied passwords being saved in plain-text anywhere.

The application has NO connectivity to the internet, so do not worry about your copied text being used for nefarious purposes. Feel free to go through the code to make sure of that.

Basic functionality

Pin

Pinning clipping will prevent them from being over-written once all existing clippings are used up.

Obfuscate

In case you copy a password and want to keep it in the tool for sometime, you can obfuscate it. It will mark it with ****. You can still copy the whole password once you click on it, it just won't show up on the application.

This is useful in case you don't want your password to be displayed as whole while you are sharing your screen with someone.

How to install

Install from binary

Download the latest go-clip.app.zip from the releases page, unzip it, and copy the .app to your Applications folder like any other application.

Since the application is not notarized, you will need to right click on the go-clip.app and choose Open.

You will see a scary message that warns you about all the bad things that the app can do to your computer. If you are paranoid (fair enough, you don't really know me that well) then you can skip to the section which builds the app from source. That way you can see what exactly the app does (You can check that the application makes no connections to the internet whatsoever).

In case you do trust me, once you click on Open, you should see the clipboard icon on your system tray. Copy a piece of text to see it on the app!

Install from source

Make sure you have go installed. Once that is done, clone this repo and run Make, it should create the go-clip.app and open the folder where it was built for you. Copy the .app to your Applications folder like any other application.

Double click on the app, and the clipboard icon should start displaying on your system tray. Copy a piece of text to see it on the app!

Future work

Thanks to github.com/getlantern/systray, I am able to provide a system tray functionality. I am waiting for fyne.io to release their integration with systray, so that I can offer a pop-out clipboard experience along with systray. Right now both systray and external app can't exist simultaneously, since both need to be executed on the main thread. (Ref https://github.com/fyne-io/fyne/issues/283)

Author: Prashantgupta24
Source Code: https://github.com/prashantgupta24/go-clip 
License: MIT license

#go #golang #clipboard 

Go-clip: A Minimalistic Clipboard Manager for Mac
Gordon  Taylor

Gordon Taylor

1650474120

Clipboard.js: Modern Copy to Clipboard. No Flash. Just 3kb Gzipped

clipboard.js

Modern copy to clipboard. No Flash. Just 3kb gzipped.

Demo

Why

Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.

That's why clipboard.js exists.

Install

You can get it on npm.

npm install clipboard --save

Or if you're not into package management, just download a ZIP file.

Setup

First, include the script located on the dist folder or load it from a third-party CDN provider.

<script src="dist/clipboard.min.js"></script>

Now, you need to instantiate it by passing a DOM selector, HTML element, or list of HTML elements.

new ClipboardJS('.btn');

Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guess what? If you have hundreds of matches, this operation can consume a lot of memory.

For this reason we use event delegation which replaces multiple event listeners with just a single listener. After all, #perfmatters.

Usage

We're living a declarative renaissance, that's why we decided to take advantage of HTML5 data attributes for better usability.

Copy text from another element

A pretty common use case is to copy content from another element. You can do that by adding a data-clipboard-target attribute in your trigger element.

The value you include on this attribute needs to match another's element selector.

example-2

<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git" />

<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
  <img src="assets/clippy.svg" alt="Copy to clipboard" />
</button>

Cut text from another element

Additionally, you can define a data-clipboard-action attribute to specify if you want to either copy or cut content.

If you omit this attribute, copy will be used by default.

example-3

<!-- Target -->
<textarea id="bar">Mussum ipsum cacilds...</textarea>

<!-- Trigger -->
<button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">
  Cut to clipboard
</button>

As you may expect, the cut action only works on <input> or <textarea> elements.

Copy text from attribute

Truth is, you don't even need another element to copy its content from. You can just include a data-clipboard-text attribute in your trigger element.

example-1

<!-- Trigger -->
<button
  class="btn"
  data-clipboard-text="Just because you can doesn't mean you should — clipboard.js"
>
  Copy to clipboard
</button>

Events

There are cases where you'd like to show some user feedback or capture what has been selected after a copy/cut operation.

That's why we fire custom events such as success and error for you to listen and implement your custom logic.

var clipboard = new ClipboardJS('.btn');

clipboard.on('success', function (e) {
  console.info('Action:', e.action);
  console.info('Text:', e.text);
  console.info('Trigger:', e.trigger);

  e.clearSelection();
});

clipboard.on('error', function (e) {
  console.error('Action:', e.action);
  console.error('Trigger:', e.trigger);
});

For a live demonstration, go to this site and open your console.

Tooltips

Each application has different design needs, that's why clipboard.js does not include any CSS or built-in tooltip solution.

The tooltips you see on the demo site were built using GitHub's Primer. You may want to check that out if you're looking for a similar look and feel.

Advanced Options

If you don't want to modify your HTML, there's a pretty handy imperative API for you to use. All you need to do is declare a function, do your thing, and return a value.

For instance, if you want to dynamically set a target, you'll need to return a Node.

new ClipboardJS('.btn', {
  target: function (trigger) {
    return trigger.nextElementSibling;
  },
});

If you want to dynamically set a text, you'll return a String.

new ClipboardJS('.btn', {
  text: function (trigger) {
    return trigger.getAttribute('aria-label');
  },
});

For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the container value.

new ClipboardJS('.btn', {
  container: document.getElementById('modal'),
});

Also, if you are working with single page apps, you may want to manage the lifecycle of the DOM more precisely. Here's how you clean up the events and objects that we create.

var clipboard = new ClipboardJS('.btn');
clipboard.destroy();

Browser Support

This library relies on both Selection and execCommand APIs. The first one is supported by all browsers while the second one is supported in the following browsers.

Chrome logoEdge logoFirefox logoInternet Explorer logoOpera logoSafari logo
42+ ✔12+ ✔41+ ✔9+ ✔29+ ✔10+ ✔

The good news is that clipboard.js gracefully degrades if you need to support older browsers. All you have to do is show a tooltip saying Copied! when success event is called and Press Ctrl+C to copy when error event is called because the text is already selected.

You can also check if clipboard.js is supported or not by running ClipboardJS.isSupported(), that way you can hide copy/cut buttons from the UI.

Bonus

A browser extension that adds a "copy to clipboard" button to every code block on GitHub, MDN, Gist, StackOverflow, StackExchange, npm, and even Medium.

Install for Chrome and Firefox.

Author: Zenorocha
Source Code: https://github.com/zenorocha/clipboard.js 
License: MIT License

#javascript #clipboard 

Clipboard.js: Modern Copy to Clipboard. No Flash. Just 3kb Gzipped

Copy to Clipboard in JavaScript | JavaScript for Beginners

Explained about

How to copy text to clipboard using Javascript.

Explained 2 easy ways to do it.

https://youtu.be/vlVBSUn6x2o

#javascript #beginners #clipboard

 

Copy to Clipboard in JavaScript | JavaScript for Beginners
Kaia  Schmitt

Kaia Schmitt

1627095600

Clipboard in Flutter | Flutter Tutorials

Clipboard in Flutter.
GitHub - https://github.com/theindianinnovation/Flutter_clipboard

#flutter tutorials #flutter #clipboard

Clipboard in Flutter | Flutter Tutorials